【问题标题】:Passing values from UIButton to an UIActionSheet将值从 UIButton 传递到 UIActionSheet
【发布时间】:2010-04-19 18:26:10
【问题描述】:

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

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

我已将 myIndexRow 声明为实例变量,并且:

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

    deleteButton.myIndexRow = myIndexRow;

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

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

【问题讨论】:

  • 上述失败。有关执行此操作的方法,请参见下面的答案。

标签: cocoa-touch uikit uibutton uiactionsheet


【解决方案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 }
}

部分答案已找到in another post and,其余部分已找到here

【讨论】:

    猜你喜欢
    • 2017-01-14
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 2015-02-03
    • 2014-01-29
    • 2013-11-25
    相关资源
    最近更新 更多