我有个问题。
单击 UITableViewCell 的子视图按钮后,我试图传递参数,这是我的源代码:
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MSContactCell *cell = (MSContactCell *)[_tableView dequeueReusableCellWithIdentifier: cellWithCheckId];
MSContact *contact = [self.list objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"MSContactCell"
owner:self
options:nil] lastObject];
cell.delegate = self;
// cell.index = indexPath.row;
cell.backgroundView.backgroundColor = [UIColor colorWithRed:0.882 green:0.863 blue:0.839 alpha:1.0];
}
cell.title.text = [contact contactName];
cell.jobTitle.text = [contact jobDescription];
cell.callButton.contactStr = [contact phoneNumber];
[cell.callButton addTarget:self action:@selector(callPressed:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
和:
- (IBAction)callPressed:(id)sender
{
contactButton *button = (contactButton *)sender;
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:@"iPhone"] ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", button.contactStr]]];
} else {
UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[Notpermitted show];
[Notpermitted release];
}
}
一切似乎都很好,但是当我调试时出现问题:
(lldb) po button
$4 = 0x2084d5a0 <MSContactCell: 0x2084d5a0; baseClass = UITableViewCell; frame = (0 0; 320 95);
autoresize = W; layer = <CALayer: 0x2085dd70>>
如何将按钮识别为按钮而不是单元格?
谢谢!