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
的设计目的。我选择了第二种方式,因为它很容易被我的代码替换。明白了。谢谢你。。。