I created a custom UITableViewCell subclass which contains a button named testbtn
. 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?
Here is my 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 ");
}