Tôi có một UITableView với các ô tùy chỉnh. Trong mỗi UITableViewCell, có một UIButton. Tôi đang cố gắng để tìm ra tế bào nút được đặt trong khi nó được khai thác. Để thực hiện điều này, tôi đã làm điều này:Sụp đổ khi gọi đến 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);
Tôi nghĩ điều này sẽ làm việc tốt, nhưng khi indexPathForCell được gọi, một ngoại lệ được ném.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell indexPathForCell:]: unrecognized selector sent to instance 0x756d650'
Bất kỳ ý tưởng nào về những gì tôi đã làm sai? Cảm ơn!
Đã hoạt động! Cảm ơn! – user2535943
lưu ý: thao tác này sẽ hoạt động trên iOS7 nhưng không hoạt động trên iOS6! –
bạn tiết kiệm thời gian của tôi, nhiều thanx. – Vigor