I\'ve a UITableViewCell
in a UITableViewController
.
In my cell there is a button that when you click takes you to another view
with a
In iOS7 UITableViewWrapperView
is the superview of UITableViewCell
, which means another superview for you:
iOS7:
UITableView *tableView = (UITableView *)cell.superview.superview;
iOS6"
UITableView *tableView = (UITableView *)cell.superview;
Another change you can find it here:
seems your code: UITableView table = (UITableView)[[[sender superview] superview] superview]; returns a UITableViewCell
not a UITableView
.
Try the below:
UITableView *table = (UITableView*)[[[[[sender superview] superview] superview] superview] superview];
I had similar problem where I had to find the textFileds value from TableView
if ([Util isiOSVerGreaterThen7]) { // iOS 7
UIView *contentView = (UIView *)[textField superview];
UITableViewCell *cell = (UITableViewCell *)[contentView superview];
UITableView *tableView = (UITableView *)cell.superview.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
NSInteger sectionOfTheCell = [indexPath section];
NSInteger rowOfTheCell = [indexPath row];
}
else { // iOS 6
UITableViewCell *cell = (UITableViewCell *)[textField superview];
UITableView *table = (UITableView *)[cell superview];
NSIndexPath *pathOfTheCell = [table indexPathForCell:cell];
NSInteger sectionOfTheCell = [pathOfTheCell section];
NSInteger rowOfTheCell = [pathOfTheCell row];
}
And Util is
+ (BOOL)isiOSVerGreaterThen7 {
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
return NO;
} else {
return YES;
}
}
This is the best way I think:
CGPoint subviewPosition = [sender convertPoint:CGPointZero toView:self.myTable];
NSIndexPath* indexPath = [self.myTable indexPathForRowAtPoint:subviewPosition];
You can simply get the index path here. Be it iOS7 or iOS6, it will return the correct index path
Apple change the UITableViewCell hierarchy in iOS 7
Using iOS 6.1 SDK
<UITableViewCell>
| <UITableViewCellContentView>
| | <UILabel>
Using iOS 7 SDK
<UITableViewCell>
| <UITableViewCellScrollView>
| | <UITableViewCellContentView>
| | | <UILabel>
So if you want to get indexpath at button index then use following code Using iOS 6 or later SDK
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *clickedButtonPath = [book_table indexPathForCell:clickedCell];
NSLog(@"index=%@",clickedButtonPath);
Using iOS 7 or 7+ SDK
UITableViewCell *clickedCell = (UITableViewCell *)[[[sender superview] superview]superview];
NSIndexPath *clickedButtonPath = [book_table indexPathForCell:clickedCell];
NSLog(@"index=%ld",(long)clickedButtonPath.item);
This is better to use
NSIndexPath *indexPath = [self.callTable indexPathForCell:(UITableViewCell *)[[[sender superview] superview] superview]];
NSLog(@"%d",indexPath.row);
It works for sure, but how super can we get?