将值从 UIButton 传递到 UIActionSheet

发布于 2024-08-29 02:54:55 字数 378 浏览 6 评论 0原文

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

我无法使用标签属性,因为它被用于其他用途。

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

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

    deleteButton.myIndexRow = myIndexRow;

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

此处明显缺少一些内容。

I'm trying to send an ActionSheet a variable from a button.

I can't use the tag property because its being used for something else.

I've declared myIndexRow as an instance variable and have:

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

    deleteButton.myIndexRow = myIndexRow;

but I'm getting the 'Request for member 'myRow' is something not a structure or union'

There is something obvious I am missing here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

避讳 2024-09-05 02:54:55

从来没想过我会回答我自己的问题,但这里是:

访问超级视图的超级视图并查询索引路径部分和行属性就可以了。

在按钮的目标中:

-(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 }
}

找到了部分答案在另一篇文章中以及其余的此处

Never figured I'd answer my own question on SO but here goes:

Accessing the superview's superview and querying the indexPath section and row properties did the trick.

In the target of the button:

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

Then down in the actionSheet's clickedButtonAtIndex method I get the row I need:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

     if (buttonIndex == 0)
        { ... doSomethingWith: actionSheet.tag }
     else
        { ... user pressed cancel }
}

Part of the answer was found in another post and and the rest here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文