1

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

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


}
4

1 回答 1

2

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

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

NSInteger section = cellIndexPath.section;

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

于 2012-04-20T10:02:32.197 回答