0

我正在尝试从按钮向 ActionSheet 发送变量。

我不能使用 tag 属性,因为它被用于其他用途。

我已将 myIndexRow 声明为实例变量并具有:

NSInteger myIndexRow = indexPath.row;
    [deleteButton addTarget:self action:@selector(showDeleteSheet:) forControlEvents:UIControlEventTouchUpInside];

    deleteButton.myIndexRow = myIndexRow;

但我收到“对成员‘myRow’的请求不是结构或联合”

我在这里缺少一些明显的东西。

4

1 回答 1

1

从来没有想过我会在 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 }
}

部分答案在另一篇文章中找到,其余部分在这里

于 2010-04-20T01:42:46.923 回答