0

私は 1 つのボタンと 1 つの uilabel を持つカスタム TableViewCell を持っています。実際、このダウンロードイベントはどこでどのように処理するのですか?ここに画像の説明を入力

これは私のカスタムセルです。私はこのように処理しようとしましたが、エラーが発生しました

*** 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");

 }
4

1 に答える 1

1

次の方法で、すべてのボタンにタグを割り当てることができます

newCell.downloadButton.tag=cell.indexPath.row

&アクションでは、ボタンタグによって押されたボタンを見つけて、すべてのボタンに異なるアクションを与えることができます。以下のメソッドを使用してボタンを見つけることができます。

UIButton *btn1 = (UIButton *)sender;

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

等々。

于 2012-05-21T12:02:01.387 に答える