2011-09-26 104 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 }