2010-05-05 53 views
1

上的UIButton聲明我有一個UITableView,每個單元內我有2個自定義按鈕,我想要做的就是withing的didSelectRowAtIndexPath方法方法我想,如果哪個按鈕被感動如果內didSelectRowAtIndexPath方法

這樣的語句做的我會有效地分裂一個細胞2

但我不知道如何我可以賴特if語句。

任何幫助將受到極大的歡迎

感謝

回答

1

感謝您幫助大家,但我找到了我所尋找的soloution。所以這裏是

在你的cellForRowAtIndexPath方法

[[cell team1Button] addTarget:self 
         action:@selector(shield1Touched:) 
      forControlEvents:UIControlEventTouchUpInside]; 

    [[cell team2Button] addTarget:self 
          action:@selector(shield2Touched:) 
       forControlEvents:UIControlEventTouchUpInside]; 

} 
[[cell team1Button] setTag:[indexPath row]]; 
[[cell team2Button] setTag:[indexPath row]]; 

設置標記,以便

,當您在自定義單元格內選擇按鈕,該應用程序知道選擇哪一行。

這樣的話你的按鈕按下方法

- (IBAction)shield1Touched:(id)sender;{ 
WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate; 

    int rowOfButton = [sender tag]; 
ScoreDetails *scoreDetail = [appDelegate.liveMatch objectAtIndex:rowOfButton]; 

,那麼你可以執行你需要根據哪個按鈕置於從細胞

希望這可以幫助別人

感動了所有的動作信息來源是here

1

我認爲蘋果的樣本的「附件」應用程序不正是你正在嘗試做的。退房MyTableViewController.m

+0

嗯,不是真的,因爲這是accesory圖像, 什麼我看如果(UIButton1收到觸摸)如果(UIButton1收到觸摸) 如果(UIButton2收到觸摸){ 如果這有幫助 – 2010-05-05 13:54:54

+0

但如果您正在尋找在UIButton中的觸摸確認,只需設置一個操作,如上所述。我在這裏錯過了什麼? – gnasher 2010-05-06 21:50:31

1

設置在一個自定義單元格的按鈕與他們 - (空)addTarget:(ID)目標採取的行動(SEL)動作forControlEvents:(UIControlEvents)controlEvents 設置爲適當的方法。

相關問題