Reputation: 39374
My code is working fine on iOS6 but crashing in iOS7.
I comparing the text field with table view cell text-field.
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
DLog(@"-> %@", textField.text);
PhotoViewCustomCell *cell = (PhotoViewCustomCell*)[[textField superview] superview];
NSIndexPath *indexPath = [tblPhotoDetail indexPathForCell:cell];
//PhotoViewCustomCell *cell = (PhotoViewCustomCell *)[tblPhotoDetail cellForRowAtIndexPath:indexPath];
PhotoInformation *objPhotoInfo = [selectedPhotos objectAtIndex:indexPath.row];
if ([textField isEqual:cell.mytextfield])
{ =========>crashing in this line
do something
}
else
{
do something
}
}
Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellScrollView mytextfield]: unrecognized selector sent to instance 0xdc119a0'
Upvotes: 0
Views: 532
Reputation: 27225
The code in Accepted Answer is not the safer one and also can't be used for iOS 6
. I'd rather recommend you to use this code. :
UIView *view = [textField superview];
while (![view isKindOfClass:[PhotoViewCustomCell class]]) {
view = [view superview];
}
PhotoViewCustomCell *cell = (PhotoViewCustomCell *)view;
Upvotes: 2
Reputation: 4817
Add additional superview call to get your cell. Looks like you are getting hidden UITableViewCellScrollView which goes in hierarchy immediately above contentView
PhotoViewCustomCell *cell = (PhotoViewCustomCell*)[[[textField superview] superview] superview];
Upvotes: 4