UIImage Methods not getting called - iphone

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

Related

UIImageview set image crash

I'm setting image to a UIImageView using in the below code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for(int i=0;i<[radioButtons count];i++){
[[radioButtons objectAtIndex:i] setImage:[UIImage imageNamed:#"checkbox_unchecked.png"]];
}
UIImageView *imageViews=(UIImageView *)[self.view viewWithTag:indexPath.row];
[imageViews setImage:[UIImage imageNamed:#"checkbox_checked.png"]];
}
So on clicking any tableview cell the images gets sets. But once if I click on objectatindex:0
then the app crashes. I'm unable to fix this.
Below is the crash log:
2012-08-20 16:25:36.321 EventApp[2422:12503] -[UIView setImage:]: unrecognized selector sent to instance 0x79642b0
2012-08-20 16:25:36.321 EventApp[2422:12503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x79642b0'
*** First throw call stack:
(0x1de3022 0x1c03cd6 0x1de4cbd 0x1d49ed0 0x1d49cb2 0x7a98c 0xc615c5 0xc617fa 0x14f685d 0x1db7936 0x1db73d7 0x1d1a790 0x1d19d84 0x1d19c9b 0x1be57d8 0x1be588a 0xbd0626 0x380a2 0x23b5)
terminate called throwing an exception(lldb)
I think you are not getting UIImageView Object,you are getting uiview types object that's why it crashes. you should try to Define another tag property like 999+indexPath.row. Got it somewhere you define the tag=0 or IB automatically takes tag=0 to all object so it taking uiview with tag 0 not uiimageView
this means that you are sending message -(void)setImage to UIView, not to UIImageView. Make sure that view with tag indexPath.row and all radioButtons in array are actually UIImageView

UITableView image causes crash

I've done a million UITables - with subtitles, images, backgrounds, colors, text-styles - you name it.
Suddenly, I'm crashing on this table, specifically on the line that calls for the image of the cell.
Here's the code:
// Configure the cell:
cell.textLabel.font = [UIFont fontWithName:#"Franklin Gothic Book" size:18];
cell.textLabel.text = [leadershipMenu objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [leadershipSubtitlesMenu objectAtIndex:indexPath.row];
// And here's the statement that causes the crash:
cell.imageView.image = [leadershipPhotosMenu objectAtIndex:indexPath.row];
Now, the error I get is this:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc'
I know for sure that the statement causing the crash is the
cell.imageView.image = ...
cause as soon as I comment it out everything works fine.
I've never in my life seen an
-[__NSCFConstantString _isResizable]:
error.
I've googled it but found very little on it.
Very peculiar.
Anyone out there got any clues?
as mentioned in your comment. the way you save your image is what causes the problem.
try this..
leadershipPhotosMenu = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:#"JohnQ.jpg"], [UIImage imageNamed:#"BillZ.png"], nil];
the code above will store the images in your mutableArray, That will work but I suggest not to store the images in an array.
you can also solve your problem without storing your images in your array like the code above by doing:
cell.imageView.image = [UIImage imageNamed:(NSString*)[leadershipPhotosMenu objectAtIndex:indexPath.row]];
this error message means your object inside your leadershipPhotosMenu is not image, but string
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc'
Do this:
cell.imageView.image = [UIImage imageNamed:[leadershipPhotosMenu objectAtIndex:indexPath.row]];
You are storing the name of the images ad not the images. However imageView has UIImage as its property and not the image name. So make below change.
cell.imageView.image = [UIImage imageNamed:[leadershipPhotosMenu objectAtIndex:indexPath.row]];

-[NSConcreteMutableData _isResizable]: issue with UIImage

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?

[__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.

IBAction being called NSCFDictionary and crashing app

I have an NSObject set up to control various elements on my screen.
I initialize the class inside my View Controller like this:
self.pageSetupClass = [[PageSetup alloc] set:self.pageID];
In IB I have added my NSObject object and linked a button to an IBOutlet on it. I've also linked it to an IBAction found in the object. When I click this button the app crashes and I get this error:
2010-09-23 15:33:11.640 BookTest10[49139:207] *** -[NSCFDictionary clickSoundByte:]: unrecognized selector sent to instance 0x4b10bc0
2010-09-23 15:33:11.641 BookTest10[49139:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary clickSoundByte:]: unrecognized selector sent to instance 0x4b10bc0'
2010-09-23 15:33:11.642 BookTest10[49139:207] Stack: (
42195024,
43352876,
42203739,
41666166,
41662962,
2915566,
3413054,
3422400,
3417197,
3042792,
2934339,
2965976,
51188092,
41474204,
41470120,
51181725,
51181922,
2958194
)
terminate called after throwing an instance of 'NSException'
There is nothing in the function at the moment so it must be the calling that crashes it...right?
If you need me to post more code I certainly can. If you have any ideas I'm all ears. Thank You
Edit:
This is the contents of the function set called out when I initialize the PageSetup object:
-(PageSetup*) set:(int) i {
self = [super init];
if(self) {
self.iD=i;
self.pageSetupFile = [[NSBundle mainBundle] pathForResource:#"PageSetup" ofType:#"plist"];
self.pageSetupArray = [[NSMutableArray alloc] initWithContentsOfFile:self.pageSetupFile];
self.pageInfo = [self.pageSetupArray objectAtIndex:self.iD];
[self initializeSoundBytes];
[self initializeAnimations];
[self initializeToys];
NSLog(#"Page Setup Initializing: %#", self.pageInfo);
return self;
}
return self;
}
Another Edit:
I set my set function to return (void) and no longer initialize it using init.
I now receive this error message:
2010-09-23 17:10:05.096 BookTest10[50519:207] *** -[UITouch clickSoundByte:]: unrecognized selector sent to instance 0x4b1b580
2010-09-23 17:10:05.097 BookTest10[50519:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITouch clickSoundByte:]: unrecognized selector sent to instance 0x4b1b580'
2010-09-23 17:10:05.099 BookTest10[50519:207] Stack: (
42166352,
43324204,
42175067,
41637494,
41634290,
2886894,
3384382,
3393728,
3388525,
3014120,
2905667,
2937304,
51159420,
41445532,
41441448,
51153053,
51153250,
2929522
)
terminate called after throwing an instance of 'NSException'
Final Edit:
I had forgotten to connect my NSObject to the File's Owner in IB.
Could it be that when I reinitialize
this object...
Wait... what? In Objective-C you never call init* methods more than once.
In any case, the underlying problem appears to be a straightforward memory management issue. Something is being released before its time and it just so happens that a dictionary lands at that location. Turn on zombie detection and it'll likely catch the problem.
self.pageSetupClass = [[PageSetup alloc] set:self.pageID];
What does set: return? Is that a method of your PageSetup class? Does it return self?
Because apparently you're assigning pageSetupClass to whatever set: returns...
Unless set: returns self, you should try this:
self.pageSetupClass = [[PageSetup alloc] init];
[self.pageSetupClass set:self.pageID];
Edit:
ok, if you added the object in IB, the object was already instantiated for you when you loaded the nib, and the IBAction and IBOutlet connections have already been made.
When you do self.pageSetupClass = ..., you're setting pageSetupClass to a new instance, and that probably leaves the button with a bad target for its IBAction.
If the object was instantiated from the nib, and you have a reference to it in pageSetupClass from a IBOutlet, then just set whatever you want in the object, no need to alloc a new one.