0

我已经手动创建了一个对象(文件 -> 新建 -> NewClass -> UITableViewCell)并将 .xib 添加到其中。创建的单元格有几个标签,见图创建单元格

之后我在其他类中使用这个对象

myCell * showHere;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"myCell" owner:self options:nil];
showHere = [nib objectAtIndex:0];

如何在此单元格上为 UIlabel 添加gestureRecognizer?

我试过这个:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
                                           initWithTarget:self 
                                           action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
[showHere.monday addGestureRecognizer:longPress];

还有这个

    -(void)handleLongPress:(UILongPressGestureRecognizer*)recognizer {
NSLog(@"label has pressed");

}

我需要按单个标签来捕捉动作。是否可以?对不起我的英语不好。

4

1 回答 1

1

YourLabel.userinteractionEnabled = YES之后添加

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 1.0;

启用对标签的触摸

祝你好运

于 2012-07-30T12:43:08.570 回答