2012-12-29 22 views
0

我有一個UITableView,並且我已將Uonable的電話號碼作爲UITableViewCell中的一個UILabel。當我單擊該特定標籤時,我應該可以撥打該特定號碼的號碼。對於UILabel響應點擊我把UITapGesture.But檢測哪個號碼被稱爲我使用的發送方標籤]其中引發錯誤:「[UITapGestureRecognizer標籤]:無法識別的選擇發送到實例」從應用程序調用電話號碼

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    lblphone = [[UILabel alloc] initWithFrame:CGRectZero]; 
      lblphone.tag = 116; 
      lblphone.backgroundColor = [UIColor clearColor]; 
      [lblphone setFont:[UIFont fontWithName:@"Helvetica" size:12]]; 
      [lblphone setLineBreakMode:UILineBreakModeWordWrap]; 
      [lblphone setUserInteractionEnabled:YES]; 
      UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelButton:)]; 
      [tapGestureRecognizer setNumberOfTapsRequired:1]; 
      [lblphone addGestureRecognizer:tapGestureRecognizer]; 
      [tapGestureRecognizer release]; 
      [cell addSubview:lblphone]; 


} 

CGSize constraint5 = CGSizeMake(320, 2000.0f); 
          CGSize size5=[phone sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14] constrainedToSize:constraint5 lineBreakMode:UILineBreakModeWordWrap]; 
          lblphone =(UILabel *)[cell viewWithTag:116]; 
          [lblphone setFrame:CGRectMake(10,businessname.frame.size.height+businessname.frame.origin.y,320, size5.height)]; 
          lblphone.textAlignment=UITextAlignmentLeft; 
          lblphone.backgroundColor=[UIColor clearColor]; 
          lblphone.numberOfLines=0; 
          lblphone.lineBreakMode=NSLineBreakByClipping; 
          lblphone.font=[UIFont fontWithName:@"Helvetica" size:14]; 
          lblphone.text=[NSString stringWithFormat:@"%@ ",phone ]; 
          [lblphone sizeToFit]; 
} 

-(IBAction)labelButton:(id)sender 
{ 

    selectedrowCall=[sender tag]; //error at this line 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://%@",[lblphone.text]]];//error at this line also :Expected Identifier 

} 

如何可以調用只有在tableviewcell中點擊的那個特定號碼?我想確認我是否能夠從模擬器測試phonecalling?

回答

2

你的問題最初在於驗證碼:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelButton:)]; 

如果你初始化UITapGestureRecognizer並設置其行動labelButton:而是因爲你沒有指定參數和方法labelButton:是要求一個id說法,一輕拍手勢識別器正在進入labelButton方法而不是UIButton,這就是爲什麼它崩潰,因爲UITapGestureRecognizer無法響應tag,它不是一個UI對象。

因此,要解決這個問題它實際上很簡單,使用此代碼:

-(IBAction)labelButton:(UITapGestureRecognizer *)sender 
{ 
    selectedrowCall=[[sender view] tag]; // here we are referencing to sender's view which is the UILabel so it works! 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://%@",[lblphone text]]];  
} 

如果這個工作,請給予好評/滴答!

+0

This worked。謝謝你 – Sindhia

+0

@辛迪亞歡迎您 – MCKapur

相關問題