Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone tableViewCell中的UITAPPgestureRecograiser_Iphone_Ios_Uitableview_Uitapgesturerecognizer - Fatal编程技术网

Iphone tableViewCell中的UITAPPgestureRecograiser

Iphone tableViewCell中的UITAPPgestureRecograiser,iphone,ios,uitableview,uitapgesturerecognizer,Iphone,Ios,Uitableview,Uitapgesturerecognizer,我在一个显示电话号码的UITableViewCell中有一个UILabel。当我点击它时,我应该能够拨打那个特定的号码。因此,为了使其可点击,我在其上添加了一个uitappesturerecognizer。但我不知道如何引用点击的点击,我指的是点击的数字 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { lblphone = [[

我在一个显示电话号码的
UITableViewCell
中有一个
UILabel
。当我点击它时,我应该能够拨打那个特定的号码。因此,为了使其可点击,我在其上添加了一个
uitappesturerecognizer
。但我不知道如何引用点击的点击,我指的是点击的数字

- (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]];
}
但每次我都能看到
NSString*phonenumber
中最后一个单元格的phonenumber


如何在
UITapGestureRecognizer
中引用单击的标签?

使用
lblphone.tag=indexPath.row+1
而不是
lblphone.tag=116位于
cellforrowatinexpath

您也可以在不使用标记的情况下实现这一点

参见下面的示例

-(void)labelButton:(UITapGestureRecognizer*)tapGestureRecognizer
{
   UILabel *phoneno = (UILabel *) tapGestureRecognizer.view;
}

为什么您使用“
UILabel
”而不是“
UIButton
”?我试过UILabel…试试这个UILabel phoneno=(UILabel)[cell viewWithTag:[TapGestureRecognitor.view.tag];您是否有任何理由特别需要使用
ui标签
而不是
ui按钮
?您可以使
ui按钮
看起来与您的
ui标签
外观完全相同,并且它可以处理它在默认情况下试图实现的所有功能。您只需将所有按钮按下挂接到一个处理程序,并使用与您现在完全相同的方法确定按下了哪个按钮。处理触摸事件是UIButton
的设计目的。我选择了第二种方式,因为它很容易被我的代码替换。明白了。谢谢你。。。