我怎样才能找到我点击的哪个部分?我需要号码将项目发送到另一个视图:
- (IBAction)mapButton:(id)sender {
UIButton * myButton = sender;
int row=myButton.tag;
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection:0];
MapViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"mapView"];
self.selectedStandort = [self.fetchedResultsController objectAtIndexPath:indexPath];
detail.currentStandort = self.selectedStandort;
[self.navigationController pushViewController:detail animated:YES];
}
答案 0 :(得分:2)
mapButton是UITableViewCell的子视图吗? 然后我会做以下事情:
NSView *contentView = [sender superview];
NSTableViewCell *cell = (UITableViewCell *)[contentView superview];
NSIndexPath *cellIndexPath = [myTableView indexPathForCell:cell];
NSInteger section = cellIndexPath.section;
您还可以使用cellIndexPath中的行,这样您就不必使标记值保持最新(例如重复使用,重新排序和删除),这会使您的实现不易出错。