如何为手动创建的对象添加gestureRecognizer?
问题描述:
我已经手动创建了一个对象(文件 - >新建 - >新建类 - > UITableViewCell)并添加了.xib。 创建细胞有多个标签,看到的景象如何为手动创建的对象添加gestureRecognizer?
后,我用这个对象在其他类
myCell * showHere;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"myCell" owner:self options:nil];
showHere = [nib objectAtIndex:0];
我怎样才能在这个小区添加gestureRecognizer为的UILabel?
我已经试过这样:
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");
}
我需要通过按单个标签上抓捕行动。可能吗? 对不起,我的英文。
答
只需添加YourLabel.userinteractionEnabled = YES
后
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 1.0;
为了使触摸到你的标签
好运
不,不'吨的工作..也许我错了水木清华.. – Arthur 2012-07-30 14:02:54
是细胞在didselectrow接收行动? – 2012-07-30 14:06:14
是的。我甚至尝试在单元类中创建识别器,但它不起作用... – Arthur 2012-07-31 08:04:48