I have created XIB for custom UITableViewCell. And inflated this in cellForRowAtIndexPath. I used cell accessoryType and UIButton above accessoryType view. So the button click event is not working. If I remove the accessoryType, it is working fine.
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
I used for button focus,
[cell bringSubviewToFront:cell.aButton];
But this also not working.
What will I do to use accessoryType and UIButton in Custom UITableViewCell?
Thanks in Advance.
You need to add the button into the contentView of the cell. You should be able to do this in interface builder or in code by
[cell.contentView addSubview: aButton];
The contentView of a tableViewCell is where objects like UIButtons and UIImageViews are placed.
Related
Hi I have two UITableView in a UIView class and are loaded with same custom UITableViewCell. Custom tableview cell contains a UITextField. That means the two UITableView contains a UITextfield of same custom cell. When I select any of that textfield, how do I know which tableView's textfield is selected? Please help me..
UITextField *txt = ----;
txt.superView.superview will give you the required UITableView instance.
To be more clear :
UITableViewCell *cell = txt.superView; // In your case custom cell
UITableView *yourTable = cell.superView;
I have a UICollectionView in every UITableViewCell of my UITableView.
The program should perform a segue there is a click on the UITableViewCell but the cell is clickable just out of the UICollectionView.
It is clickable just in the red portions.
Do you have any ideas?
You need to disable user interaction in each collection view:
In your storyboard uncheck here:
Or in your cellForRowAtIndexPath:
cell.collectionView.userInteractionEnabled = NO;
I have a prototype cell which with a button and a label in it. The text of the label changes for each cell. I have set up an #IBAction for the button and would like to get the text for the label in the cell in which the button in pressed. Does anyone know how to do this?
In didSelectRowAtIndexPath method you can get selected cell using
cellForRowAtIndexPath using indexPath.row
when you get selected cell object you can access that label which present inside the cell.
I hope it will help you.
- (IBAction)buttonHandler:(id)sender{
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview;
println("%#",cell.textLabel.text)
}
I followed UISwitch in a UITableView cell to put a UISwitch inside a tableview. Here is the code:
UISwitch *mySwitch = [[UISwitch alloc] init];
cell.accessoryView = mySwitch;
But the problem is that when I put the table into editing mode:
self.tableView.editing = YES;
The UISwitch dissapears.
Do you know how can I go around this issue?
Add UISwitch to contentView of cell.
The contentView of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the contentView so they will be positioned appropriately as the cell transitions into and out of editing mode.
[[cell contentView] addSubview:switch];
I have a custom UITableViewCell that has 2 UITextFields and a UIButton. The text fields are set in the cell:ForRow:AtIndexPath: method. What I need is to change the opacity of this UIButton dynamically, without having to reload the entire tableview. I was thinking of something like cellForRowAtIndexPath:, but how to access the outlet in this cell?
Thanks
When you create the cell in cellForRowAtIndexPath: just maintain a pointer to it in code. If that button is on every cell then you can just create an array of buttons so that you can easily access the button for the cell you want.
UIButton *cellButton = [[UIButton alloc] init];
[allCellButtons addObject:cellButton];