如何获取所选自定义TableViewCell的节号?

时间:2012-04-20 09:51:34

标签: ios xcode uitableview

我怎样才能找到我点击的哪个部分?我需要号码将项目发送到另一个视图:

- (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];


}

1 个答案:

答案 0 :(得分:2)

mapButton是UITableViewCell的子视图吗? 然后我会做以下事情:

NSView *contentView = [sender superview];
NSTableViewCell *cell = (UITableViewCell *)[contentView superview];
NSIndexPath *cellIndexPath = [myTableView indexPathForCell:cell];

NSInteger section = cellIndexPath.section;

您还可以使用cellIndexPath中的行,这样您就不必使标记值保持最新(例如重复使用,重新排序和删除),这会使您的实现不易出错。

相关问题