如果您的表格只有一个部分,您可以在标签中存储显示操作表的哪一行,如下所示。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSString *title = [NSString stringWithFormat:@"Sheet for row %i", indexPath.row];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Option 1", @"Option 2", nil];
[sheet setTag:indexPath.row];
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
int row = actionSheet.tag;
NSLog(@"Selected actionSheet buttonIndex %i for row: %i", buttonIndex, row);
}
这可能是最简单的方法,但我不会说这是最好的方法。