Iphone Can';当按下UITableViewCell中的按钮时,无法启动呼叫

Iphone Can';当按下UITableViewCell中的按钮时,无法启动呼叫,iphone,uitableview,uibutton,call,Iphone,Uitableview,Uibutton,Call,我的tableview中的每个单元格都有一个按钮。按下按钮时我想拨一个号码。我以前使用过这样的代码调用: NSString *cifra1=@"tel://"; NSString *cifra=customer.tel; cifra1 = [cifra1 stringByAppendingString:cifra]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra1]]; 如果我把这段代码放在

我的tableview中的每个单元格都有一个按钮。按下按钮时我想拨一个号码。我以前使用过这样的代码调用:

NSString *cifra1=@"tel://";
NSString *cifra=customer.tel;     
cifra1 = [cifra1 stringByAppendingString:cifra];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra1]];
如果我把这段代码放在方法“didSelectRowAtIndexPath”中,一切都会正常工作。但是如果我把它放在
-(iAction)按钮按下:(UIButton*)发送者中,什么都不会发生。我用NSLog检查了这个方法,它对按钮点击做出响应

怎么了

编辑:奇怪,这是有效的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


NSString *cifra1=@"tel://";
NSString *cifra=@"123456789";
cifra1 = [cifra1 stringByAppendingString:cifra];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra1]];
}

尽管正确读取了客户编号,但这并不正确:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

Customer *c=[customerArray objectAtIndex:indexPath.row];

NSString *cifra1=@"tel://";
NSString *cifra=c.tel;
cifra1 = [cifra1 stringByAppendingString:cifra];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra1]];

}是你按下的按钮叫什么

尝试添加
NSLog(@“%s”,函数)

尝试使用id而不是UIButton:

-(IBAction)buttonPressed:(id) sender
(iAction)按钮按下:(UIButton*)发送器

将其更改为(iAction)按钮按下:(id)发件人执行此操作

NSString *cifra = [[c.tel copy] autorelease];

我怀疑您正在使用核心数据。

请确保使用
addTarget:action:withObject:forControlEvents:

设置按钮的目标,即
customer.tel
。这在不同的行中有所不同吗?如果是这样的话,如何从
-buttonPressed:
方法中引用它。你能按顺序显示didSelectRowAtIndexPath的完整代码吗?我能说出(iAction)buttonPressed:(UIButton*)中的错误sender@Deepak:当按下按钮,一切正常时,我记录了custoemr.tel的号码,我得到了正确的号码。你能把这两种方法都贴出来吗?它在一种方法中工作而不是在另一种方法中工作似乎很奇怪。buttonPressed调用成功,问题不在这里。这没有帮助,而且我没有使用核心数据。只有使用NSString*cifra=@“123456789”使字符串文字化才有效。我不明白。在
openURL:
之前,
cifra1
的值是多少?你能用
NSLog
检查一下吗?