2011-09-26 103 views
1

我分類了UITableViewCell並使用IB添加了一個圓形記錄按鈕。自定義TableViewCell問題

通常情況下,該事件將在類我自定義的UITableViewCell的處理。

但是,如何處理這個按鈕被點擊了的viewController擁有使用此的UITableViewCell一個UITableView的事件?

回答

0

在創建自定義單元格,請確保您添加的視圖控制器的按鈕操作的目標。因此,在您的視圖控制器(假設它是表視圖的數據源):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // All your standard identifier & dequeueing stuff here 
    if (cell == nil) 
    { 
     // We are creating a new cell, let's setup up its button's target & action 
     cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     [cell.yourButton addTarget:self action:@selector(yourAction:) forControlEvents:UIControlEventTouchUpInside]; 
    } 
    return cell; 
} 
+0

按鈕這工作每次按鈕被竊聽。但是,我如何通過它被點擊到選擇器的indexpath? –

+0

我已經解決了與http://stackoverflow.com/questions/7044532/pass-parameter-through-selector –

+0

你可以通過調用超級超級搶表視圖單元格的引用引用問題上(即兩次)按鈕。那麼這只是使用tableview的indexpathforcell方法的問題。 – Rog

0

所以它有點akward的ü正在做的方式,因爲什麼ü真正想要做的就是創建的UIView的子類,然後創建並將其添加到單元格的contentView。但因爲你這樣做,你應該設置按鈕的標籤到它的索引,然後在選擇器中有函數說cancelButton:然後這應該是你的cancelButton函數刪除 - (void)cancelButton:(id)sender { 的UIButton 壓=(的UIButton)發送者; //然後在代碼傳遞PF與pressed.tag }