-[NSConcreteMutableData _isResizable]: issue with UIImage - iphone

I am getting the error below:
-[NSConcreteData _isResizable]: unrecognized selector sent to instance 0x9954d30
on this code:
UIImage *cachedImage = [self cachedImageForUrl:self.imageSource];
if (cachedImage) {
self.image = cachedImage;
}
any idea?

Are you using ARC? If not, this can happen when self.image doesn't correctly retain the cachedImage. When cachedImage gets dealloc'ed and self tries to access it, that memory might now point to random other classes (like NSConcreteData). How did you define the #property for UIImage *image?

Related

UIImage isKindOfClass issue

This is my code in my application,
[imageview setAlpha:1.0f];
[imageview setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#.png",[pages objectAtIndex:swipeCount]]]];
[imageview setFrame:CGRectMake(-300, 0, 1368, 1000)];
Edit:
pages = [[NSArray alloc] initWithObjects:#"page1",#"page2",#"page3",#"page4",#"page5",#"page6",#"page7b",#"page8",#"page9",#"page10a",#"page11",#"page12",#"page13b",#"page14",#"page15",#"page16a",#"page17",#"page18",#"page19",#"page20",#"page21",#"page22",#"page23",#"page24",#"page25", nil];
imageview=[[UIImageView alloc]init];
its working properly, problems except when the app enters background and comes back to foreground shows the following error,
*** -[UIImage isKindOfClass:]: message sent to deallocated instance 0x1e8b10
What wrong with the code?
Please help me out
Yes, you need to allocate memory to your UIImage. What is basically happening is that your image is being temporarily stored in the memory and deallocated upon closing the app so iOS could allocate that memory to more immediate needs. You can fix that as below. I'm also gonna allocate a string since stringWithFormat returns an autorelease String.
NSString *imageName = [[NSString alloc] initWithFormat::#"%#.png",[pages objectAtIndex:swipeCount]];
UIImage *myImage = [UIImage imageNamed:myImage];
[imageview setImage:image];
Try using properties. Make array,imageView as a property and then use
self.pages and self.imageView
see this good article on properties
Objective-c properties

UIImage Methods not getting called

I'm trying to manipulate UIImage Object on the view. But when I try to call any method on UIImage class, it throws exception
2013-02-14 15:24:42.301 Test[4685:19a03] -[UIImage scaleToSize:]: unrecognized selector sent to instance 0x94642c0
2013-02-14 15:24:42.303 Test[4685:19a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage scaleToSize:]: unrecognized selector sent to instance 0x94642c0'
*** First throw call stack:`
(0x1cc1012 0x1ae6e7e 0x1d4c4bd 0x1cb0bbc 0x1cb094e 0x47ee9 0x47bc0 0xb0f817 0xb0f882 0xb0fb2a 0xb26ef5 0xb26fdb 0xb27286 0xb27381 0xb27eab 0xb27fc9 0xb28055 0xc2d3ab 0xa7e92d 0x1afa6b0 0x5c3fc0 0x5b833c 0x5b8150 0x5360bc 0x537227 0x5378e2 0x1c89afe 0x1c89a3d 0x1c66f61 0x1c66e1b 0x39117e3 0x3911668 0xa2e65c 0x31fcd 0x29d5)
libc++abi.dylib: terminate called throwing an exception
Here's the code that I'm using:
UIImage *test = [[UIImage alloc] init];
test = [UIImage imageNamed:#"image0.jpg"];
[test scaleToSize:CGSizeMake(40.0f, 40.0f)];
Take a look at the UIImage's class reference. You won't find the method you are looking for. Maybe you forgot to add a category you are using like (for example):
#import "UIImage+Scale.h"
FIRST DEFINE THE IMAGE SIZE THEN SCALE IT.
UIImage *test = [[UIImage alloc] init;
test = [UIImage imageNamed:#"image0.jpg"];
[test scaleToSize:CGSizeMake(40.0f, 40.0f)];
Try this line of code.Or use this image in UIImageView

_NSCFConstantString CGImage]: unrecognized selector sent to instance

App is crashing with error _NSCFConstantString CGImage]: unrecognized selector sent to instance
when trying app with this code to save image to photo album
int currentimage = _imageScrollView.contentOffset.y / [pictures count];
UIImage *imageToShow = [pictures objectAtIndex:currentimage];
UIImageWriteToSavedPhotosAlbum(imageToShow, self, #selector(image: didFinishSavingWithError:contextInfo:), nil);
By the information that you gave in the comments, you are using an UIImage reference ("imageToShow") that is pointing to a NSString (element from the array), and that is why when imageToShow receive the CGImage selector, crashes.
To solve this problem, you have to put UIImage references to UIImage objects in the array.
UIImage *image0 = [UIImage imageWithContentsOfFile:"image0FullPath.png"];
UIImage *image1 = [UIImage imageWithContentsOfFile:"image1FullPath.png"];
pictures = [[NSArray alloc] initWithObjects:image0, image1, nil];
If the images are in the mainbundle, you can use imageNamed instead of imageWithContentsOfFile. imageNamed receive as input only the name of the file, and search for it inside the mainbundle. imageWithContentsOfFile needs the full path.
Good Luck!

[__NSArrayM synchronize]: unrecognized selector exception

I used some NSMutableArray with UIImageView objects.
When I quit the app I get this exception message:
[__NSArrayM synchronize]: unrecognized selector sent to instance 0x4b3a910
In AppDelagate.m
NSMutableArray * aViewArray;
...
currentView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:displayImageNamed]];
[aViewArray addObject:currentView];
[currentView release];
In ViewController.m
UIImageView *myImage = [aViewArray objectAtIndex:i];
myImage.xxx = yyy ;
Looking at your comment regarding NSUserDefaults, you should not be releasing both languages and defaults since you don't have ownership (you didn't alloc/init them). Try removing those two calls to release and see if that resolves your issue.

Why is this leaking memory? UIImage `cellForRowAtIndexPath:`

Instruments' Leaks tells me that this UIImage is leaking:
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:#"/%#.png", [postsArrayID objectAtIndex:indexPath.row]]]];
// If image contains anything, set cellImage to image. If image is empty, try one more time or use noImage.png, set in IB
if (image != nil){
// If image != nil, set cellImage to that image
cell.cellImage.image = image;
}
image = nil;
[image release];
(class cell (custom table view cell) also releases cellImage in dealloc method).
I haven't got a clue of why it's leaking, but it certainly is.
The images gets loaded multiple times in a cellForRowAtIndexPath:-method. The first three cells' image does not leak (130px high, all the space avaliable).
Leaks gives me no other info than that a UIImage allocated here in the code leaks.
Can you help me figure it out? Thanks :)
The code you have there would be correct if image was a #property. You can release a #property by doing self.property = nil because of the way the setter works. The setter releases the old object and sets the ivar to the value. In order to fix this you would need to put [image release] first. What is happening here is that you set image to nil and then you are essentially doing [nil release]. The old image is just floating around somewhere. So to fix this do the following:
[image release];
image = nil;
You are setting it to nil before calling release. So you are releasing nil instead of image.
Change from:
image = nil;
[image release];
to:
[image release];
image = nil;
Little bit code modification
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath
stringByAppendingPathComponent:[NSString stringWithFormat:#"/%#.png",
[postsArrayID objectAtIndex:indexPath.row]]]];
if (image){
cell.cellImage.image = image;
[image release];