UIImageView initWithCoder - 无法识别的选择器发送到实例... iOS 5 beta SDK

时间:2011-08-11 09:11:17

标签: iphone uiimageview uiactivityindicatorview ios5 xcode4.2

如果已经被问过我很抱歉,但问题出现了:

我最近将我的SDK更新为 iOS 5测试版。我的应用程序在新模拟器上构建并运行完美,但是当我尝试将部署目标更改为较旧的iOS( 4.3 )时,应用程序在尝试使用 UIActivityIndi​​catorView时立即崩溃/ strong>控制(模拟器和设备)。我在一个非常简单的加载视图中使用 UIActivityIndi​​catorView ,该视图仅包含 View UIActivityIndi​​catorView

当我从该视图中删除 UIActivityIndi​​catorView 控件时,视图工作正常,应用程序在加载其他视图(带有活动指示符和图像)时崩溃。所以,长话短说:app在iOS 5环境中运行良好,但图像和活动指示器在旧iOS版本上运行时会崩溃。有什么想法吗?

提前致谢!

修改

我正在添加一些代码,只是为了向您展示我如何使用该视图。它真的不多, LoadingViewController 本身绝对没有自定义代码(所有控件都在nib中)。

if(!self.loadingScreen){
    self.loadingScreen = [[LoadingViewController alloc] initWithNibName:@"LoadingViewController" bundle:nil];
}
[self.view addSubview:loadingScreen.view];

异常消息实际上并没有多说,但是你去了:

0   CoreFoundation                      0x017bd5a9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x01911313 objc_exception_throw + 44
2   CoreFoundation                      0x017bf0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x0172e966 ___forwarding___ + 966
4   CoreFoundation                      0x0172e522 _CF_forwarding_prep_0 + 50
5   UIKit                               0x00f8e9fd UINibDecoderDecodeObjectForValue + 2592
6   UIKit                               0x00f8f6ac -[UINibDecoder decodeObjectForKey:] + 398
7   UIKit                               0x00d75db0 -[UIImageView initWithCoder:] + 97

3 个答案:

答案 0 :(得分:2)

我有同样的问题,只是找到了解决方案。 我的UIActivityIndi​​cator已添加到xib文件中。我已经从xib中删除它并通过代码创建它(activityIndi​​cator = [[UIActivityIndi​​catorView alloc] initWithActivityIndi​​catorStyle:...)。

现在一切都好,它有效!

我希望这会对你有所帮助。

答案 1 :(得分:1)

按照smith324的建议,我开始浏览Apple dev论坛,看看我是做错了什么,或者SDK中是否有错误。事实证明,最新版本中有一个令人讨厌的错误,就像我的情况一样崩溃UIImages,UIActivityIndi​​cators等。好消息是,确实存在解决方法,您可以在此处找到它:https://devforums.apple.com/message/507796#507796

感谢大家的帮助!

编辑:

如果您无法访问该链接,建议的答案是:

@implementation UIImage (initWithCoder)

- (id)initWithCoder:(NSCoder *)aDecoder
{
     return nil;
}

@end

答案 2 :(得分:1)

我无法打开网址https://devforums.apple.com/message/507796#507796 ....但我认为您可以为UIImage类创建一个类别,如下所示:

@implementation UIImage (Coder)

- (id)initWithCoder:(NSCoder *)aCoder
{
     return nil;
}

@end