UISwitch setThumbTintColor导致崩溃(仅限iOS 6)? [英] UISwitch setThumbTintColor causing crash (iOS 6 only)?

查看:165
本文介绍了UISwitch setThumbTintColor导致崩溃(仅限iOS 6)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppDelegate的代码中有这个:

I have this in the code for my AppDelegate:

- (void) customizeAppearance {
    [[UISwitch appearance] setOnTintColor:[UIColor colorWithRed:0 green:175.0/255.0 blue:176.0/255.0 alpha:1.0]];
    [[UISwitch appearance] setTintColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1.000f]];
    [[UISwitch appearance] setThumbTintColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]];
 }

然后我从 - (BOOL)应用程序调用:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

我也使用ARC。在iOS 6中,我的应用程序一直在崩溃。我启用了NSZombie,它一直说: *** - [UIDeviceRGBColor release]:消息发送到解除分配的实例0x9658eb0

I also use ARC. In iOS 6 my app keeps crashing. I enabled NSZombie and it keeps saying: *** -[UIDeviceRGBColor release]: message sent to deallocated instance 0x9658eb0

现在我已经意识到上面的一个完全可重复的流程。当我在customizeAppearance中单独注释掉setThumbTintColor行时,一切正常。当我使用setThumbTintColor代替时,应用程序每次都以完全相同的方式崩溃。

And now I've realized one perfectly reproducible flow for the above. When I comment out the setThumbTintColor line alone inside customizeAppearance, then everything works fine as it should. When I use the setThumbTintColor line instead, the app crashes the exact same way every time.

这是UISwitch / setThumbTintColor / UIColor的任何人都知道的问题吗?如果不是开关颜色,还有什么原因?

Is this a known issue to anyone with UISwitch/setThumbTintColor/UIColor? What else could be the cause if not the switch color?

推荐答案

我还在做这个教程并遇到了同样的问题。 (不知道为什么你没有遇到这种情况,因为我输入的代码和解决方案代码对我来说都有同样的问题?)

I was also doing this tutorial and had the same problem. (Not sure why you don't experience this, as both my hand typed in code and the solution code have the same problem for me?)

第一个segue会发生好的,但是在返回之后下一个segue会失败。

The first segue would happen ok, but after going back the next segue would fail.

设置全局异常断点后,我可以在生成异常时看到调用堆栈中的thumbColorTint。我猜测对象太早发布了。为了解决这个问题,我在我的app委托中创建了一个属性..(你不需要在app中委托你只设置UISwitch外观的对象,在我的例子中是appdelegate)

After setting a global exception breakpoint I could see thumbColorTint in the call stack when the exception was generated. I made a guess that the object was being released too early. To fix I created a property in my app delegate..(you don't need to do it in the app delegate just the object that you are setting the UISwitch appearance, which in my case was the appdelegate)

@interface SurfsUpAppDelegate()
@property (strong, nonatomic) UIColor *thumbTintColor;
@end

然后我将其设置为

[self setThumbTintColor:[UIColor colorWithRed:0.211 green:0.550 blue:1.000 alpha:1.000]];
[[UISwitch appearance] setThumbTintColor:[self thumbTintColor]];

现在一切正常,因为对象未提前发布。这可能是一个缺陷,即使仍然需要对象也会被释放。 UISwitch似乎有API的缺陷:(

And now everything works as expected as the object is not released early. This is probably a defect and the object is released even though it is still needed. UISwitch seems to have a defect for the API :(

这篇关于UISwitch setThumbTintColor导致崩溃(仅限iOS 6)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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