Neeraj Neeru
Neeraj Neeru

Reputation: 570

handle buttonEvent for UITableViewCell?

i have a custom TableViewCell with one button and One uilabel. actually where do mi handle this download event and how?enter image description here

this is my custom cell. i tried to handle like this but got the error

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

my code is here

 - (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;
}

what is the real code for handling button event from cell?

edits

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

 }

Upvotes: 0

Views: 134

Answers (1)

Aakil Ladhani
Aakil Ladhani

Reputation: 982

You can assign tag to each and every button by

newCell.downloadButton.tag=cell.indexPath.row

& in action u can find which button has been pressed by button tag and give different action to all the button. You can use below method to find button.

UIButton *btn1 = (UIButton *)sender;

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

and so on.

Upvotes: 1

Related Questions