Note that there are some explanatory texts on larger screens.

plurals
  1. POAssign UIButton event dynamically in UITableViewCell
    primarykey
    data
    text
    <p>I created a custom UITableViewCell subclass which contains a button named <code>testbtn</code>. I then tried to assign an event of that button to another class, but that isn't working for me. Please can you tell me where I am going wrong?</p> <p>Here is my code:</p> <pre><code> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"PatientCell"; PatientCell *cell = (PatientCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { NSArray *TopLevelOb = [[NSBundle mainBundle] loadNibNamed:@"PatientCell" owner:self options:nil]; for (id currentlevelob in TopLevelOb) { if([currentlevelob isKindOfClass:[PatientCell class]]){ cell = (PatientCell *) currentlevelob; cell.test.text = @"some text"; cell.HR.text =@"80"; cell.ABP.text =@"120/20"; cell.SOP2.text =@"95"; cell.RR.text=@"98"; [cell.testbtn addTarget:self action:@selector(openLiveData:) forControlEvents:UIControlEventTouchUpInside];// **this event is not fire to openLiveData method** break; } } } else { NSArray *TopLevelOb = [[NSBundle mainBundle] loadNibNamed:@"PatientCell_iPad" owner:self options:nil]; for (id currentlevelob in TopLevelOb) { if([currentlevelob isKindOfClass:[PatientCell class]]){ cell = (PatientCell *) currentlevelob; cell.test.text = [nameArry objectAtIndex:indexPath.row]; cell.HR.text =@"80"; cell.ABP.text =@"120/20"; cell.SOP2.text =@"95"; cell.RR.text=@"98"; [cell.testbtn addTarget:self action:@selector(openLiveData:) forControlEvents:UIControlEventTouchUpInside]; break; } } } } return cell; } -(IBAction)openLiveData:(id)sender{ NSLog(@"hello "); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload