cuốn sách gpt4 ai đã làm

ios - 尝试添加 UITapGestureRecognizer 但不工作

In lại Tác giả: Walker 123 更新时间:2023-11-29 03:13:47 25 4
mua khóa gpt4 Nike

我尝试在 UILabel 上设置一个简单的 UITapGestureRecognizer,但它不起作用。似乎没有任何内容被识别,也没有任何内容写入日志。

在从 viewDidLoad 调用的方法中

  UILabel *miTN = [[UILabel alloc] initWithFrame:CGRectMake(300, 100, 150, 15)];
[miTN setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized)];
[miTN addGestureRecognizer: tapRecognizer];
[miView addSubview:miTN];

... later

- (void)tapRecognized:(id)sender
{
NSLog(@"that tap was recognized");
}

另外,这是响应异步网络调用而调用的。这可能是导致问题的原因吗?是否有其他问题可能导致问题?我不太确定调试的第一步是什么 - 我检查了颜色混合图层以查看它们是否重叠但看起来不是。

câu trả lời hay nhất

您应该将 UIGestureRecognizerDelegate 添加到您的 View Controller 类的协议(protocol)列表中

@interface TSViewController : UIViewController 

并插入字符串:

tapRecognizer.delegate = self;

并替换

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized)];

ĐẾN

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];

关于ios - 尝试添加 UITapGestureRecognizer 但不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21919155/

25 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress