我手动创建了一个对象(File - > New - > 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");
}
我需要按下单个标签来捕捉行动。可能吗? 抱歉我的英文。
答案 0 :(得分:1)
在
之后添加YourLabel.userinteractionEnabled = YES
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
启用标签的触摸
祝你好运