从来没有想过我会在 SO 上回答我自己的问题,但这里是:
访问超级视图的超级视图并查询 indexPath 部分和行属性就可以了。
在按钮的目标中:
-(void)showDeleteSheet:(id)sender {
NSIndexPath *indexPath = [table indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
NSInteger currentSection = indexPath.section;
NSInteger currentIndexRow = indexPath.row;
//form the actionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete this item?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete"
otherButtonTitles:nil];
actionSheet.tag = currentIndexRow;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
[actionSheet release];
}
然后在 actionSheet 的 clickedButtonAtIndex 方法中,我得到了我需要的行:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{ ... doSomethingWith: actionSheet.tag }
else
{ ... user pressed cancel }
}
部分答案在另一篇文章中找到,其余部分在这里