更新:收到一封来自苹果的邮件,说bug/问题现在已经修复了,下一个SDK版本不会有这个问题。安息吧!
我在我的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)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
调用它
我也使用ARC。在iOS 6中,我的应用程序总是崩溃。我启用了NSZombie,但它一直显示:*** -[UIDeviceRGBColor release]: message sent to deallocated instance 0x9658eb0
现在我已经实现了上述的一个完全可重复的流程。当我在customizeAppearance中单独注释掉setThumbTintColor行时,一切都正常工作。当我使用setThumbTintColor行时,应用程序每次都以完全相同的方式崩溃。
使用UISwitch/setThumbTintColor/UIColor的任何人都知道这是一个问题吗?如果不是开关颜色,还可能是什么原因?
发布于 2012-10-23 02:48:47
我也在做this教程,也遇到了同样的问题。(不知道为什么你没有体验到这一点,因为我的手输入代码和解决方案代码对我来说都有相同的问题?)
第一个段可以正常运行,但在返回后,下一个段将失败。
在设置了全局异常断点之后,当异常生成时,我可以在调用堆栈中看到thumbColorTint。我猜测这个对象发布得太早了。为了解决这个问题,我在我的应用程序委托中创建了一个属性。。(你不需要在应用程序委托中做这件事,只需要设置UISwitch外观的对象,在我的例子中就是应用程序委托)
@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似乎有一个接口的缺陷:(
发布于 2013-04-19 09:53:29
我也遇到了苹果UISwitch过度发布的问题。我有一个类似的解决方案,但我认为它更好一点,因为它不需要添加无关的属性:
UIColor *thumbTintColor = [[UIColor alloc] initWithRed:red green:green blue:blue alpha:alpha]];
//we're calling retain even though we're in ARC,
// but the compiler doesn't know that
[thumbTintColor performSelector:NSSelectorFromString(@"retain")]; //generates warning, but OK
[[UISwitch appearance] setThumbTintColor:[self thumbTintColor]];
缺点是,它确实创建了一个编译器警告,但是--这里真的有一个bug,只是不是我们的!
发布于 2013-06-18 12:29:41
现在,我采用的是per Bill的回答:
// SomeClass.m
@interface SomeClass ()
// ...
@property (weak, nonatomic) IBOutlet UISwitch *thumbControl;
@property (strong, nonatomic) UIColor *thumbControlThumbTintColor;
// ...
@end
@implementation SomeClass
// ...
- (void)viewDidLoad
{
// ...
self.thumbControl.thumbTintColor = self.thumbControlThumbTintColor = [UIColor colorWithRed:0.2 green:0.0 blue:0.0 alpha:1.0];
// ...
}
// ...
@end
https://stackoverflow.com/questions/12972500
复制相似问题