如何向UIView添加触摸事件?
我尝试:
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, nextY)] autorelease];
[headerView addTarget:self action:@selector(myEvent:) forControlEvents:UIControlEventTouchDown];
// ERROR MESSAGE: UIView may not respond to '-addTarget:action:forControlEvents:'
Run Code Online (Sandbox Code Playgroud)
我不想创建子类和覆盖
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud) 有没有人有任何示例代码来检测动态创建的UIView上的触摸?我找到了一些touchesBegan的引用,但无法弄清楚如何实现它...