UIButton在自定义UIView中的麻烦
我有一个简单的(基于视图的)应用程序。我想点击自定义 UIView,我的按钮移动到该视图内的某个位置(例如指向 10,10)。
- 我的自定义 UIView 是 DrawView(DrawView.h 和 DrawView.m)。
- RotatorViewController(h.和.m)。
我向我的 DrawView 添加一个 UIButton,连接我的 DrawView 和 UIButton 的插座。我在 RotatorViewController 和 @selector(tap:) 中添加 UITapGestureRecognizer。 的代码
- (void)viewDidLoad { [super viewDidLoad]; UIGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:drawView action:@selector(tap:)]; [drawView addGestureRecognizer:tapGR]; [tapGR release]; }
这是 UITapGestureRecognizer @selector(tap:)
- (void) tap:(UITapGestureRecognizer *)gesture { myButton.transform = CGAffineTransformMakeTranslation(10, 10); }
,但是当我点击 DrawView 应用程序中的任何位置时都会崩溃。这是来自控制台的日志
2011-02-23 20:59:24.897 Rotator[7345:207] -[DrawView tap:]: unrecognized selector sent to instance 0x4d0fa80 2011-02-23 20:59:24.900 Rotator[7345:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DrawView tap:]: unrecognized selector sent to instance 0x4d0fa80'
我需要你的帮助
I have a simple (view-based) application. I want on tapping on custom UIView my button moved somewhere inside that view (for example to point 10,10).
- My custom UIView is DrawView (DrawView.h and DrawView.m).
- RotatorViewController (h. and .m).
I add to my DrawView an UIButton, connect with outlets my DrawView and UIButton. I add UITapGestureRecognizer in RotatorViewController and @selector(tap:).
Here is code of UITapGestureRecognizer
- (void)viewDidLoad { [super viewDidLoad]; UIGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:drawView action:@selector(tap:)]; [drawView addGestureRecognizer:tapGR]; [tapGR release]; }
@selector(tap:)
- (void) tap:(UITapGestureRecognizer *)gesture { myButton.transform = CGAffineTransformMakeTranslation(10, 10); }
But when i tap anywhere in DrawView application crashes. Here is log from console
2011-02-23 20:59:24.897 Rotator[7345:207] -[DrawView tap:]: unrecognized selector sent to instance 0x4d0fa80 2011-02-23 20:59:24.900 Rotator[7345:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DrawView tap:]: unrecognized selector sent to instance 0x4d0fa80'
I need your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
你说:
你写道:
UIGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:drawView action:@selector(tap:)];
这意味着操作是在drawView委托中执行的,但您定义了选择器
tap:< /code> 在
RotatorViewController
中。我认为你只需要将目标
drawView
替换为self
UIGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)] ;
You said :
and you wrote :
UIGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:drawView action:@selector(tap:)];
It means the actions is performed in the drawView delegate but you defined the selector
tap:
in theRotatorViewController
.I think you just have to replace the target
drawView
byself
UIGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];