2011-05-19 64 views
0

我的tableview中的每个单元格都有一个按钮。我想在按下按钮时拨打一个号码。我用从代码之前调用是这样的:按下UITableViewCell中的按钮时无法启动呼叫

NSString *[email protected]"tel://"; 
NSString *cifra=customer.tel;  
cifra1 = [cifra1 stringByAppendingString:cifra]; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra1]]; 

如果我的方法把这个代码“didSelectRowAtIndexPath方法”一切正常。但如果我把它放在-(IBAction)buttonPressed:(UIButton *) sender什么都不会发生。我用NSLog检查了这个方法,它响应按钮点击。

出了什么问题?

编辑:奇怪,这个工程:

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


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

}

和这并不,evethough客户数量正确读取:

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

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

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

}

+0

你如何获得的电话号码,即'customer.tel'。这是不同的行不同?如果是的话,如何从'-buttonPressed:'方法中引用它。 – 2011-05-19 12:53:00

+0

你可以显示完整的代码didSelectRowAtIndexPath为了我可以说什么是错误的(IBAction)buttonPressed:(UIButton *)发件人 – 2011-05-19 12:53:30

+0

@Deepak:我记下从custoemr.tel号码时按下按钮,一切都很好,我得到正确的号码。 – DixieFlatline 2011-05-19 13:10:22

回答

0

这是你的buttonPressed叫什么名字?

尝试添加NSLog(@"%s", __FUNCTION__);

尝试使用ID代替的UIButton:

-(IBAction)buttonPressed:(id) sender 
+0

buttonPressed被调用。 – DixieFlatline 2011-05-19 13:55:45

0

(IBAction为)buttonPressed:(UIButton的*)发件人

改变它(IBAction为)buttonPressed :(id)寄件人

+0

这是没有必要的。 – 2011-05-19 12:50:03

+0

这没有帮助。 – DixieFlatline 2011-05-19 13:08:44

0

这样做

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

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

+0

这没有帮助,我没有使用核心数据。只有用NSString * cifra = @“123456789”才能生成字符串文字。我没有明白。 – DixieFlatline 2011-05-19 14:08:28

+0

'openURL:'之前'cifra1'的值是什么?你可以检查一个'NSLog'吗? – 2011-05-19 14:10:15

+0

它返回正确的东西,“tel:// 123456789” – DixieFlatline 2011-05-19 15:09:05

0

确保您设置按钮的目标与addTarget:action:withObject:forControlEvents:

+0

buttonPressed调用成功,问题不在这里。 – DixieFlatline 2011-05-19 14:00:55