objective-c - iOS UI 外观错误

标签 objective-c xcode ios5 uiappearance

我正在构建一个文件管理应用程序,在调用 UIImagePickerControllerMPMediaPickerController 时偶尔会出现以下错误:

*** -[_UIImageViewPretiledImageCacheKey hash]: message sent to deallocated instance 0x140dc0

我最近使用 iOS 5 的 UIAppearance API 为我的应用程序提供了一个自定义主题,那时我开始收到此错误。通过猜测和检查,我发现了导致此错误的代码中有问题的行:

UIImage *backButtonImage = [[UIImage imageNamed:@"backButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 16, 12, 8)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
UIImage *barButtonImage = [[UIImage imageNamed:@"barButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(14, 12, 14, 12)];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

我不知道这段代码是如何触发上述错误的。能否请您向我解释此错误的来源并提供修复它的解决方案。

在此先感谢您的帮助, 古维

最佳答案

经过一些更彻底的测试,我得出的结论是这个问题仅限于 Retina 设备。问题原来出在@2x 图像中。它们的分辨率为奇数(例如 59px x 60px)。我所做的只是重新创建图像并将分辨率更改为 60px x 60px,我再也没有遇到过这个问题。

我对这个解决方案感到有点惊讶,因为我发现错误消息和代码行之间没有关联,但最终,是图像导致了这个问题。

关于objective-c - iOS UI 外观错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11131123/

相关文章:

ios - 如何保持 iOS 应用程序的干净生产版本?

ios - 使用自定义 segue 在导航堆栈上向后移动

iphone - 为什么 Emoji 无法在 UITextField 中正确显示?

objective-c - 跟踪方法 iOS 的进度?

ios - RTCVideoCapturer 捕获器WithDeviceName :(NSString*) becomes very slow after subsequent calls

objective-c - 使用发件人和对象发布通知

ios - IOS8中出现错误“沙箱拒绝iokit-get-properties”

objective-c - Xcode 中 2 个第三方库的重复符号问题

ios - AFNetworking 和后台传输

iphone - iOS 应用程序基准测试