2010-04-19 49 views
0

我试图从一个按钮发送一个ActionSheet变量。将UIButton中的值传递给UIActionSheet

我不能使用标签属性,因为它被用于别的东西。

我已经声明myIndexRow作为一个实例变量,有:

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

    deleteButton.myIndexRow = myIndexRow; 

,但我发现myRow的“会员申请'的东西不是一个结构或联合”

有我很想念这里。

+0

以上失败。请参阅下面的答案,了解如何执行此操作。 – 2010-04-20 01:43:59

回答

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