という名前のボタンを含むカスタム UITableViewCell サブクラスを作成しましたtestbtn
。次に、そのボタンのイベントを別のクラスに割り当てようとしましたが、うまくいきません。どこが間違っているのか教えてください。
これが私のコードです:
- (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 ");
}