gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:31:12 25 4
gpt4 key购买 nike

我手动创建了一个对象(文件 -> 新建 -> NewClass -> UITableViewCell)并向其中添加了 .xib。创建的cell有几个标签,见图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");

我需要通过按单个标签来捕捉 Action 。是否可以?对不起我的英语。

最佳答案

只需在

之后添加 YourLabel.userinteractionEnabled = YES

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer 分配]
initWithTarget: self
Action :@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;

启用对标签的触摸

祝你好运

关于objective-c - 如何为手动创建的对象添加gestureRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11721563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com