I've a grouped UITableView
with several custom cells where I placed text fields. I have defined a property pointing to the text field that is currently active:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
self.activeTextField = textField;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
self.activeTextField = nil;
}
I need to get the row and section of the cell containing such text field. I tried this:
UITableViewCell *parentCell = (UITableViewCell *)[self.activeTextField superview];
NSIndexPath* cellPath = [self.tableView indexPathForCell:parentCell];
NSInteger cellRow = [cellPath row];
But I always get a 0. It looks like parentCell
is not an UITableViewCell
actually (but it should be). How can I get those values?
Thanks
If you are adding the text view to cell's container view then you have to call self.activeTextField.superview.superview
. If not, self.activeTextField.superview
should work.
In order to find out if your text field is added to container view's cell:
[cell addSubview:]
then is in cell's view[cell.cotentView addSubView:]
then is in container view.