2010-04-19 63 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