0

I customized the tableView cell which I set a label of time & What I need if I touch/click the label it show the text of that label.

Here is the time label set:

cell.time.text = @"5 mins ago";
cell.time.tag = 1;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[cell.time setUserInteractionEnabled:YES];
[cell.time addGestureRecognizer:tap];

So when I tapped the label must do the below

-(void)tapAction:(id)sender
{
    // I want to get the text of that label for above example must return

    // 5 mins ago
}

Thanks in advance..

4

4 回答 4

1

您可以访问点击查看

-(void)tapAction:(id)sender
{
    UITapGestureRecognizer *tapRec = (UITapGestureRecognizer *)sender;
    UILabel *label = (UILabel *)tapRec.view;
    NSLog(@"%@",label.text);
}
于 2013-04-18T12:41:46.147 回答
0

尝试这个

-(void)tapAction:(id)sender
{
    UITapGestureRecognizer *recognizer = (UITapGestureRecognizer *)sender;
    UILabel *label = (UILabel *)recognizer.view;
    NSString *text = label.text;
}
于 2013-04-18T12:35:20.877 回答
0

你为什么不使用委托方法而不是在你的单元格上设置一个手势识别器呢?

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

}

然后,您可以从 indexPath 中提取行,并知道选择了哪个单元格。

于 2013-04-18T12:28:10.430 回答
0

使用下面的代码

cell.time.text = @"5 mins ago";
cell.time.tag = [indexpath.row];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[cell.time setUserInteractionEnabled:YES];
[cell.time addGestureRecognizer:tap];


-(void)tapAction:(id)sender
{
 UIbutton *btn = (UIbutton *)sender
 Nsstring *str = [btn.text]
// I want to get the text of that label for above example must return

// 5 mins ago
}
于 2013-04-18T12:28:35.807 回答