[英]UIControl subclass is unable to take a target?
我是UIControl的子类,我发送它:
[self sendActionsForControlEvents:UIControlEventValueChanged];
当我创建对象的实例时,我按如下方式添加目标:
[starView addTarget:self action:@selector(starRatingChanged:) forControlEvents:UIControlEventValueChanged];
视图显示正常,没有目标在那里功能很好。 但是添加目标后,它会崩溃。 有什么想法吗?
我的班级声明:
@interface RMStarRating : UIControl {...}
为了它的价值,我在- (void)layoutSubviews
设置了我的视图。 是否有另一种方法需要进行子类化以便正确保存目标或者为目标发送正确的操作? 我以为UIControl会为您保存目标和操作。
更新:尝试提供更多信息
我将对象设置如下:
RMStarRating *starView = [[RMStarRating alloc] initWithFrame:CGRectMake(10, 70, 23*5, 30)];
[starView addTarget:self action:@selector(starRatingChanged:) forControlEvents:UIControlEventValueChanged];
....
[self.view addSubview:starView];
根据乔丹的建议,我的sendAction:
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
NSLog(@"send action");
[super sendAction:action to:target forEvent:event];
}
我的函数调用sendActionsForControlEvents:
- (void)updateValue:(UITouch *)touch {
....
NSLog(@"sendActionsForControlEvents");
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
应该调用的函数(它也在标题中):
- (void)starRatingChanged:(id)sender {
NSLog(@"star rating changed");
}
日志只是吐出来的:
2010-10-22 09:45:41.348 MyApp[72164:207] sendActionsForControlEvents
2010-10-22 09:45:41.350 MyApp[72164:207] send action
调试器具有:
你试过实施吗?
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event
代替? 一个很好的例子就在这里:
好的,我知道它是什么。 我过早地发布了我的父类,所以即使它在屏幕上显示,也没有消息被发回的对象。
我最终不需要sendAction:to:forEvent。
乔丹,谢谢你的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.