我试图创建一个程序,当我点击屏幕时,会弹出警报.. 所以我将UIView更改为UIControl,并创建一个IBAction方法当点击屏幕时,然后我在互联网上找到一个方法打印点击位置。
这是我的代码:
-(IBAction) Touch:(id)sender{
[self touchesBegan];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [[touches allObjects] objectAtIndex: 0];
CGPoint currentPos = [myTouch locationInView: self];
NSLog(@"Point in myView: (%f,%f)", currentPos.x, currentPos.y);
}
它给我一个错误...... 怎么办?!?!
答案 0 :(得分:1)
从“触摸”方法中删除[self touchesBegan]
你是
1. calling this method without the necessary parameters, so you are
probably getting unrecognized selector sent to instance,
2. the uiview calls this method on its own, you just need to override it