UIControl子类无法采取目标? [英] UIControl subclass is unable to take a target?

查看:52
本文介绍了UIControl子类无法采取目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UIControl的子类,并且在其中发送:

I've subclasses UIControl and in it I am sending:

[self sendActionsForControlEvents:UIControlEventValueChanged];

当创建对象的实例时,我将添加一个目标,如下所示:

When I create an instance of the object, I add a target as follows:

[starView addTarget:self action:@selector(starRatingChanged:) forControlEvents:UIControlEventValueChanged];

该视图显示良好,并且在没有目标的情况下,该功能运行良好.但是添加目标后,它就会崩溃.有什么想法吗?

The view shows up fine, and without the target being there the functionality works well. But with adding the target, it crashes. Any ideas why?

我的班级宣告为:

@interface RMStarRating : UIControl {...}

关于它的价值,我在-(void)layoutSubviews 中设置了视图.我是否需要子类化另一种方法,以便正确保存目标或向目标发送正确的操作?我认为UIControl可以为您保存目标和操作.

For what it is worth, I set up my view in - (void)layoutSubviews. Is there another method that I need to subclass in order for the targets to be saved properly or for the targets to be sent the right actions? I thought UIControl handled saving the targets and actions for you.

更新:尝试提供更多信息

UPDATE: trying to provide more information

我将对象设置如下:

RMStarRating *starView = [[RMStarRating alloc] initWithFrame:CGRectMake(10, 70, 23*5, 30)];
[starView addTarget:self action:@selector(starRatingChanged:) forControlEvents:UIControlEventValueChanged];
....
[self.view addSubview:starView];

根据约旦的建议,我的sendAction:

My sendAction, according to Jordan's suggestion:

- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
    NSLog(@"send action");
    [super sendAction:action to:target forEvent:event];
}

我的调用sendActionsForControlEvents的函数:

My function that calls sendActionsForControlEvents:

- (void)updateValue:(UITouch *)touch {
    ....
    NSLog(@"sendActionsForControlEvents");
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}

应该调用的函数(它也位于标头中):

And the function that should be called (and it is in the header too):

- (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

调试器具有:

推荐答案

好,我知道是什么了.我太早释放了我的父类,因此即使该消息显示在屏幕上,也没有对象可以发送回该消息.

Ok, I figured out what it was. I was releasing my parent class too soon, so there was no object for the message to be sent back to, even though it was showing on screen.

最后我不需要sendAction:to:forEvent.

And I ended up not needing the sendAction:to:forEvent.

乔丹,谢谢您的帮助.

这篇关于UIControl子类无法采取目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆