[__NSArrayM synchronize]: unrecognized selector exception - iphone

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.

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

Loop through UITextField's and store double values

I'm having trouble looping through a set of dynamically created UITextFields and storing those values as a double to be added to an array later on. I'm still pretty new to obj-c programming so bear with me if this question seems trivial. Thanks. This is what I have so far.
NSMutableArray *textFieldCashArray = [[NSMutableArray alloc] init];
double textFieldCash;
for (int y=0; y<25; y++) {
UITextField *myLabel = (UITextField *)[self.view viewWithTag:y];
textFieldCash = [myLabel.text doubleValue];
[textFieldCashArray addObject:[NSNumber numberWithDouble:textFieldCash]];
}
P.S and here is the error message I'm getting
Pro[962:b303] -[UIControl text]: unrecognized selector sent to instance 0x680f850
2012-04-01 16:05:46.305 iFinance Pro[962:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIControl text]: unrecognized selector sent to instance 0x680f850'
*** Call stack at first throw:
I think what's going on here is that the loop variable is being used as the tag, and the loop starts at zero. viewWithTag will answer either the receiver or one of it's subviews with a given tag, so if the view controller's main view has tag==0 (which it probably does), your first text request is being sent to that top-level view.
Try setting the text field tags to some non-zero value, starting at SOME_OFFSET. Then in your loop:
for (y=0; y<25; y++) {
UITextField *myLabel = (UITextField *)[self.view viewWithTag:y+SOME_OFFSET];
// ...
}
danh is most certainly right about the cause and solution to this problem. Just to add a little, cases like this can be somewhat avoided by checking the Class before casting.
if ([[self.view viewWithTag:y] isKindOfClass:[UITextField class]]) {
UITextField *myLabel = (UITextField *)[self.view viewWithTag:y];
textFieldCash = [myLabel.text doubleValue];
[textFieldCashArray addObject:[NSNumber numberWithDouble:textFieldCash]];
}
You should create array at first:
NSMutableArray *textFieldCashArray = [NSMutableArray array];
Edit
Your error log shows that you are receiving some another UIControl object (UIBtton for example) instead of UITextField. Check your tags on xib (or algorith if you set programmatically) and be sure that UITextField objects has corresponding tags

-[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?

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.