我有一個UILabel
在UITableViewCell
顯示電話號碼。當我點擊它時,我應該可以打電話給那個特定的號碼。所以爲了使它可點擊,我添加了一個UITapGestureRecognizer
它。但我無法知道如何引用哪個點擊,我的意思是點擊哪個數字。tableViewCell中的UITapgestureRecogniser
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
lblphone = [[UILabel alloc] initWithFrame:CGSizeMake(20,30,50,100)];
lblphone.tag = 116;
lblphone.backgroundColor = [UIColor clearColor];
lblphone.text=[NSString stringwithFormat:@"%@",phone];
[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];
}
-(IBAction)labelButton:(UITapGestureRecognizer*)tapGestureRecognizer
{
NSIndexPath *indexPath;
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UILabel *phoneno = (UILabel*)[cell viewWithTag:116];
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:phoneno.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
}
但是每當我看到最後一個單元格的PHONENUMBER在NSString *phoneNumber
;
我該如何參考UITapGestureRecognizer
中點擊哪個標籤?
見實例爲什麼要使用 「'UILabel'」 而不是 「'UIButton'」? – 2013-03-16 08:22:43
我試過UILabel ... – Honey 2013-03-16 08:24:52
試試這個UILabel * phoneno =(UILabel *)[cell viewWithTag:[tapGestureRecognizer.view.tag]]; – 2013-03-16 08:34:36