Error IIA UIAppearance

I create a file management application and sometimes get the following error when calling UIImagePickerController or MPMediaPickerController :

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

I recently gave my application a custom theme using the IOS 5 UIAppearance API, and when I started getting this error. Guessing and checking, I found 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 do not know how this code causes the above error. Could you explain to me the source of this error and provide a solution to resolve it.

Thanks in advance for your help, Guvvy

+6
source share
3 answers

After more rigorous testing, I came to the conclusion that this problem is limited to retinal devices. The problem turned out to be @ 2x images. They had an odd numerical resolution (e.g. 59 pixels by 60 pixels). All I did was recreate the image and change the resolution from 60 pixels to 60 pixels, and I never experienced a problem again.

I was surprised by the solution because I did not see the correlation between the error message and the line of code, but in the end it was the images that caused this problem.

+3
source

I had a similar problem , but my failure was caused by image resizing in UIImageView .

My resized image has edge inserts on top = 30px, left = 20px, bottom = 1px, right = 10px. The image is 43x45, so its variable area is 13x14. I use iOS6, so I was able to solve the problem by specifying UIImageResizingModeStretch as resizingMode for -[UIImage resizableImageWithCapInsets:resizingMode:] .

Works:

 UIImage *image = [UIImage imageNamed:name]; UIImage *resizableImage = [image resizableImageWithCapInsets:edgeInsets resizingMode:UIImageResizingModeStretch]; 

Crash with EXC_BAD_ACCESS or [_UIImageViewPretiledImageCacheKey hash]: message sent to deallocated instance 0xb14deb0 using NSZombieEnabled :

 UIImage *image = [UIImage imageNamed:name]; UIImage *resizableImage = [image resizableImageWithCapInsets:edgeInsets]; 
+2
source

I got the same for the following code

 UIImage* image = [UIImage stretchableImageNamed:@"imageName"]; self.backgroundView = [[UIImageView alloc] initWithImage:image]; self.selectedBackgroundView = [[UIImageView alloc] initWithImage:image]; 

where self is a UITableViewCell and stretchableImageNamed: is just

 +(UIImage*)stretchableImageNamed:(NSString*)name { UIImage *img = [UIImage imageNamed:name]; CGSize sz = img.size; int left = (sz.width - 1.) / 2.; int top = (sz.height - 1.) / 2.; return [img resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, top, left)]; } 

That helped:

 self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage stretchableImageNamed:@"imageName"]]; self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage stretchableImageNamed:@"imageName"]]; 
0
source

Source: https://habr.com/ru/post/918623/


All Articles