我有一个UITableView自定义单元格。在每个UITableViewCell中,都有一个UIButton。我试图找出按钮在被点击时位于哪个单元格中。要做到这一点,我已经做到了这一点:调用时崩溃indexPathForCell
- (IBAction)likeTap:(id)sender {
UIButton *senderButton = (UIButton *)sender;
UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview];
UITableView* table = (UITableView *)[buttonCell superview];
NSIndexPath *pathOfTheCell = [table indexPathForCell:buttonCell];
NSInteger rowOfTheCell = [pathOfTheCell row];
NSLog(@"rowofthecell %d", rowOfTheCell);
我认为这将很好地工作,但是当indexPathForCell被调用时,会抛出异常。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell indexPathForCell:]: unrecognized selector sent to instance 0x756d650'
什么,我做错了任何想法? 谢谢!
它的工作!谢谢! – user2535943
注意:这将适用于iOS7,但不适用于iOS6! –
你节省了我的时间,很多thanx。 – Vigor