UISwitch的初始化导致iOS 6中无法识别的选择器异常 [英] Initialization of UISwitch causes unrecognized selector exception in iOS 6

查看:123
本文介绍了UISwitch的初始化导致iOS 6中无法识别的选择器异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有一个UISwitch,并且在设备和模拟器上都可以在iOS 7上正常运行,但是当我在iOS 6模拟器上运行应用程序时,出现一个奇怪的异常.

I have a UISwitch in my view and everything works fine for iOS 7 both on my device and the simulator, but when I run my application in the iOS 6 simulator I get a weird exception.

异常断点在以下特定代码行触发:

The exception breakpoint fires at this particular line of code:

self.mySwitch = [[UISwitch alloc] init];

具有以下输出:

-[__NSCFString count]: unrecognized selector sent to instance

这是模拟器中的错误吗?我不知道如何解决此问题,目前还没有iOS 6设备.

Is this somehow a bug in the simulator? I have no idea how to fix this and at the moment I don’t have an iOS 6 device at hand.

此时相关的堆栈跟踪为:

The relevant stack trace at this point is:

* thread #1: tid = 0x177e6, 0x0191be52 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread, stop reason = breakpoint 1.1
frame #0: 0x0191be52 libobjc.A.dylib`objc_exception_throw
frame #1: 0x01d144bd CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 253
frame #2: 0x01c78bbc CoreFoundation`___forwarding___ + 588
frame #3: 0x01c7894e CoreFoundation`_CF_forwarding_prep_0 + 14
frame #4: 0x01c0ab10 CoreFoundation`CFArrayGetCount + 80
frame #5: 0x0106cc04 UIKit`__36-[_UISwitchInternalView _labelImage]_block_invoke_0 + 144
frame #6: 0x010a22fe UIKit`+[UIImage(_UIImageTintedInterfaceExtension) _cachedImageForKey:fromBlock:] + 131
frame #7: 0x0106cb6c UIKit`-[_UISwitchInternalView _labelImage] + 187
frame #8: 0x0106e6ed UIKit`-[_UISwitchInternalView _buildControl] + 1454
frame #9: 0x0106b7c1 UIKit`__39-[_UISwitchInternalView initWithFrame:]_block_invoke_0 + 36
frame #10: 0x00eb240c UIKit`+[UIView(Animation) _performWithoutAnimation:] + 82
frame #11: 0x0106b793 UIKit`-[_UISwitchInternalView initWithFrame:] + 420
frame #12: 0x0106f196 UIKit`-[UISwitch _commonInitNewLook] + 225
frame #13: 0x0106f741 UIKit`-[UISwitch initWithFrame:] + 143
frame #14: 0x0106f6ab UIKit`-[UISwitch init] + 118

关于UIAppearance,我仅使用了两个调用,即使我将它们注释掉,也会发生崩溃.

I use only two calls regarding UIAppearance and the crash occurs even when I comment them out.

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor slubDarkBlue]];
[[UISearchBar appearance] setImage:[UIImage imageNamed:@"searchBarIcon"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

推荐答案

开发者论坛中的Apple Developer使我朝着正确的方向前进.原来这是一个本地化问题.

An Apple Developer in the Developer Forums got me in the right direction. Turns out it was a localization issue.

我做到了:

[myUserDefaults setObject:inAppLanguage forKey:@"AppleLanguages"];

代替:

[myUserDefaults setObject:@[inAppLanguage] forKey:@"AppleLanguages"];

其中inAppLanguage是NSString,例如@"de"或@"en".因此,UISwitch遇到单个NSString而不是NSStrings的NSArray.

where inAppLanguage is a NSString like @"de" or @"en". So the UISwitch encountered the single NSString instead of an NSArray of NSStrings.

这篇关于UISwitch的初始化导致iOS 6中无法识别的选择器异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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