如何为手动创建的对象添加gestureRecognizer?

时间:2012-07-30 12:26:40

标签: objective-c ios ipad

我手动创建了一个对象(File - > New - > NewClass - > UITableViewCell),并添加了.xib。 创建的单元格有多个标签,请参见图片created Cell

之后我在其他类

中使用此对象
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");

}

我需要按下单个标签来捕捉行动。可能吗? 抱歉我的英文。

1 个答案:

答案 0 :(得分:1)

之后添加YourLabel.userinteractionEnabled = YES

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

启用标签的触摸

祝你好运