处理UITableViewCell的buttonEvent?

时间:2012-05-21 11:34:17

标签: events uitableview uibutton

我有一个带有一个按钮和一个uilabel的自定义TableViewCell。实际上mi在哪里处理这个下载事件以及如何处理?enter image description here

这是我的自定义单元格。我试图像这样处理,但得到了错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-    [downloadPageCell downloadSong:]: unrecognized selector sent to instance 0x94b1490'
*** First throw call stack:

我的代码在这里

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  downloadPageCell *newCell = nil;

  newCell = [tableView dequeueReusableCellWithIdentifier:identifier];

   if(newCell == nil)
   {
     NSLog(@"newCell ===================");
     NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"downloadPageCell" owner:self options:nil];
     newCell  = [ nibViews lastObject];
  }

  newCell.titleText.text=[URLTitle objectAtIndex:indexPath.row];

    [newCell.downloadButton addTarget:self action:@selector(DOWNLOAD:) forControlEvents:UIControlStateNormal];

return newCell;
}

从单元格处理按钮事件的真实代码是什么?

编辑

   -(void)downloadButtonPressed:(UIButton*)sender
 {
   NSLog(@"download button pressed");

 }

1 个答案:

答案 0 :(得分:1)

您可以通过

为每个按钮指定标签
newCell.downloadButton.tag=cell.indexPath.row

&安培;在操作中你可以找到按钮标签按下了哪个按钮,并对所有按钮给出不同的动作。 您可以使用以下方法查找按钮。

UIButton *btn1 = (UIButton *)sender;

if(btn1.tag==1) {
  // call action for that first cell button
}

等等。