我使用多个循环在3个级别创建子菜单,方法是将UIGestureRecognizer
分配给UILabel
。我得到一些非常奇怪的行为;在任何情况下,事件仅针对菜单的前三个元素抛出。无论他们是2级,3级还是两者。我尝试使用UIButton
而不是UILabel
,我得到完全相同的行为。
将UILabel
添加到UIView
内的某些UIScrollView
。
以下是代码:
for(NSDictionary* sub in [category objectForKey:@"sub"]) {
// First level
if([sub valueForKey:@"sub"]) {
// Second level
for(NSDictionary* sub2 in [sub objectForKey:@"sub"]) {
// Third level (links)
for(NSDictionary __strong *video in [sub2 objectForKey:@"video"]) {
// Label handler tap
labelCat.tag = i;
labelCat.userInteractionEnabled = YES;
[videos insertObject:[[video objectForKey:@"src"] objectForKey:@"text"] atIndex:i]; i++;
singleFingertap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showVideo:)];
[labelCat addGestureRecognizer:singleFingertap];
[view3 addSubview:labelCat];
}
}
} else {
// Label handler tap
labelCat.tag = i;
[videos insertObject:[[video objectForKey:@"src"] objectForKey:@"text"] atIndex:i]; i++;
singleFingertap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showVideo:)];
labelCat setUserInteractionEnabled:YES];
[labelCat addGestureRecognizer:singleFingertap];
}
}
对于动作处理程序:
- (void)showVideo:(UITapGestureRecognizer *)sender
{
NSLog(@"test");
}
你知道这里发生了什么吗? 感谢