2011-04-18 105 views
0

我在我的tableView中使用CustomCell,只有幾個按鈕和標籤。現在我想給這些按鈕提供一些操作。任何人都可以幫助我如何爲我的UIButton使用Action?TableView自定義單元格UIButton動作

的界面:

-(IBAction)btnAction; 

在執行:

-(IBAction)btnAction 
{ 
    [self Evaluate:(int *)1 :(int *)2]; 
} 

現在告訴我,我該怎麼分配在一個UIButton的行動我的UIButton在我的手機?

回答

0

您可以使用addTarget:action:forControlEvents:方法(UIControl的一個方法,其中UIButton是一個子類)以編程方式向UIButton添加一個操作。

所以您的實現看起來是這樣的:

[myButton addTarget:self 
      action:@selector(btnAction) 
    forControlEvents:UIControlEventTouchUpInside]; 

希望這有助於。

+0

@StuDev:我有BeginingCell.h和BeginingCell.m爲CustomCell.And我在GameTableView(另一個類)中使用它。在哪裏應該把這些代碼? – 2011-04-18 06:29:52

+0

@ sohel_14_cse_ju:如果我理解正確,我會說,一個好方法是在BeginingCell類中使用UIButton(使用@property聲明,並使用@synthesize生成訪問器/增變器),以便您可以從你的GameTableView訪問它。然後,當你在GameTableView中初始化你的單元格時,你會做類似'[myBeginningCell.theButton addTarget:action:forControlEvents]'(假設你的BeginingCell.h中的button屬性被稱爲'theButton')。 – Stuart 2011-04-18 06:44:33

+0

我的outlet是在beginingCell中定義的。根據你的指導,這是正常的。我只是想嘗試像這樣[BeginingCellObject.ansBtn1 addTarget:btnAnsEval:forControlEvents];與btnAnsEval Method.Bit錯誤,它顯示它沒有聲明。但我在tableView類中正確地做了。任何想法是怎麼回事? – 2011-04-18 08:30:03

相關問題