Search code examples
objective-cxcodeios5uiappearance

iOS UIAppearance Error


I'm building a file management app, and I occasionally get the following error while calling a UIImagePickerController or a MPMediaPickerController:

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

I recently gave my app a custom theme using iOS 5's UIAppearance API and thats when I started getting this error. By guessing and checking, I found the problematic lines of my code that cause this error:

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];

I have no idea how this code triggers the above error. Can you please explain to me the source of this error and provide a solution to fix it.

Thanks in advance for your help, Guvvy


Solution

  • After some more thorough testing, I have reached the conclusion that this problem is limited to retina devices. The issue turned out to be in the @2x images. They had a odd numbered resolution (eg. 59px by 60px). All I did was recreate the image and changed the resolution to 60px by 60px and I never experienced the problem again.

    I was kind of surprised by the solution as I saw no correlation between the error message and the line of code, but in the end, it was the images that caused this problem.