When I use base cell (UITabelViewCell) with disclosure indicator and enabled selection, selection occurs by click anywhere in row.
But when I use custom class for cell with UITextField selection occurs only by click outside UITextField. How can I fix it?
you can set the userInteractionEnabled = NO for textfield.
but if you do this, the textfield won't be selected anymore.
When you use a custom cell which has UITextField embedded inside it, the click on UITextfield will call the UITextField Delegate method not any UITableView delegate method. If you need to select the Custom cell you have to write the code explicitly inside the UITextField delegate method. In order to identify which cell has the UITextField you can use tag property of UITextField which can mention the cell identifier.
Related
I am new to iOS. I need to show the Label in timeDelay in UITableViewCell only when its visible?
Create a custom UITableView cell. In your cellForRowIndexPath, call the function performSelectorWithDelay which will show your UILabel.
When the cellForRowIndexPath is called, it's pretty certain that the cell will now be shown.
I have a custom UITableViewCell, and I would like to add a custom accessory type to it. I can set the custom accessory type in the cellForRowAtIndexPath, but I don't think that is an ideal way.
Question:
How can I set a custom accessory type to a custom cell?
You can just assign a custom UIView (image,button, etc..) to the property
cell.accessoryView = <your custom view>;
If the custom accessoryView is different in every cell the in the delegate method
cellForRowAtIndexPath:
you can create the assignment, if it is the same in each cell then you can subClass a UITableViewCell (follow this tutorial Link)
So i have a custom UITableViewCell which contains three UILabel. The UITableViewCell is such that the UILabel completely cover the cell.
Now i want to detect whenever user taps on the cell. Problem is as the UILabel cover the cell I cannot use UITableView delegate method for detecting touch on the cell.
I thoughout about using gesture recoginzers on the UILabel but then i don't get the index of the touched cell. I also thought about placing a transparent button on top of the cells but here there is also the same problem that i can't get the index of the touched cell.
Can anybody guide me with an approach on how can i accomplish detecting taps with tableView didSelectRowAtIndexPath when UILabel are covering the cell.
Try to set userInteractionEnabled to false in all labels in cell. This will pass touch to the cell and then you can use UITableView delegates. Be sure that cell stays userInteractionEnabled = YES
To get the touch event besides didSelect method try this. In your custom cell class add a block like,
typedef void(^TappedCell)(CustomCell *cell);
and add a property for it,
#property (nonatomic, strong) TappedCell tappedCell;
and on transparent button action
- (IBAction)buttonTapped {
if (self.tappedCell) {
self.tappedCell(self);
}
}
And in cellForRow method
__weak type(self)weakSelf = self;
cell.tappedCell = ^ (CustomCell *tappedCell) {
//Ur actions goes here
//for getting index
NSIndexPath *indexPath = [weakSelf.tableView indexPathForCell:tappedCell];
[weakSelf someActionWithIndexPath:indexPath];
};
It doesnt matter whether UILabel hide your cell or UIImageView hide it. It will automatically detects tableView didSelectRowAtIndexPath. Check it first you wont face any problems. Did you try to implement tableview in detail first
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];
I have a custom uitableviewcell with a textfield in it. To input text into the textfield I am using a custom keyboard. However, when a keyboard button is pressed, my method fails to update the text in the textfield. When I check the cell that I've grabbed, I find that it is empty. Here is the code I use:
VariableCellController *cell = (VariableCellController *)[equationViewController.variableTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[equationViewController.selectedVariableRow intValue] inSection:0]];
Where VariableCellController is the uitableviewcell controller and the equationViewController is a property of my CustomNumberPadViewController.
It seems as if my instantiation of equationViewController is not the one actually showing...
Got it, I added a textfield as a property in my keyboard controller class and passed the handle to the text field to the keyboard controller in the textfielddidbeginediting method.