我曾尝试在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");
}此外,这是为了响应异步网络调用而调用的。这可能是导致问题的原因吗?是否还有其他可能导致问题的问题?我真的不确定调试的第一步是什么-我检查了颜色混合层,看看他们是否重新映射,但似乎不是。
发布于 2014-02-21 04:50:30
您应该将UIGestureRecognizerDelegate添加到视图控制器类的协议列表中
@interface TSViewController : UIViewController <UIGestureRecognizerDelegate>并插入字符串:
tapRecognizer.delegate = self;并替换
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized)];至
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];https://stackoverflow.com/questions/21919155
复制相似问题