02-07-2010, 03:53 PM
#1 (permalink )
Registered Member
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Getting Variables from a NSMutableArray
Hi,
I am trying to get NSStrings from a NSMutableArray, but my app is crashing...
Here is my Code - the app is crashing on "branch = [....]; but the NSMutableArray is filled with (see test below)...
Code:
showData = [[NSMutableArray alloc]init];
branch =[showData objectAtIndex:0];
company = [showData objectAtIndex:1];
name = [showData objectAtIndex:2];
phone = [showData objectAtIndex:3];
email = [showData objectAtIndex:4];
price = [showData objectAtIndex:5];
notes = [showData objectAtIndex:6];
NSLog(@"The Branch: %@", company);
My NSMutable Array:
New Array: 12, 13, 14, 15, 16, 19, 18
Test: INSERT OR REPLACE INTO PARTNER (branche, company, name, phone, email, price, notes ) VALUES ('12', '13', '14', '15', '16', '19', '18');
Crashlog: New Array: 12, 13, 14, 15, 16, 19, 18
2010-02-07 21:28:00.956 WPlite[9034:207] *** -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x3b77970
2010-02-07 21:28:00.957 WPlite[9034:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x3b77970'
May you please can point me to the right direction...
Thanks for any advice,
Stefan
Last edited by StefanL; 02-07-2010 at 03:56 PM .
02-07-2010, 05:01 PM
#2 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 24
Where do you fill the Array with data?
showData = [[NSMutableArray alloc] init] creates a new and empty array.
The code seems to be right for me, if you fill the array between the first and second line.
The error says, that you try to call the method objectAtIndex from a String: [NSCFString objectAtIndex:]
If you copy the whole code, we can have a look at it.
Quote:
Originally Posted by
StefanL
Hi,
I am trying to get NSStrings from a NSMutableArray, but my app is crashing...
Here is my Code - the app is crashing on "branch = [....]; but the NSMutableArray is filled with (see test below)...
Code:
showData = [[NSMutableArray alloc]init];
branch =[showData objectAtIndex:0];
company = [showData objectAtIndex:1];
name = [showData objectAtIndex:2];
phone = [showData objectAtIndex:3];
email = [showData objectAtIndex:4];
price = [showData objectAtIndex:5];
notes = [showData objectAtIndex:6];
NSLog(@"The Branch: %@", company);
My NSMutable Array:
New Array: 12, 13, 14, 15, 16, 19, 18
Test: INSERT OR REPLACE INTO PARTNER (branche, company, name, phone, email, price, notes ) VALUES ('12', '13', '14', '15', '16', '19', '18');
Crashlog: New Array: 12, 13, 14, 15, 16, 19, 18
2010-02-07 21:28:00.956 WPlite[9034:207] *** -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x3b77970
2010-02-07 21:28:00.957 WPlite[9034:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x3b77970'
May you please can point me to the right direction...
Thanks for any advice,
Stefan
02-07-2010, 05:21 PM
#3 (permalink )
Registered Member
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Quote:
Originally Posted by
seb_bue
Where do you fill the Array with data?
showData = [[NSMutableArray alloc] init] creates a new and empty array.
The code seems to be right for me, if you fill the array between the first and second line.
The error says, that you try to call the method objectAtIndex from a String: [NSCFString objectAtIndex:]
If you copy the whole code, we can have a look at it.
Hi Seb,
thanks for your reply:
Code:
-(void)viewDidLoad {
NSLog(@"New Array: %@", showData);
NSString *branch =[showData objectAtIndex:0];
NSLog(@"Die Firma: %@", branch);
NSString *company = [showData objectAtIndex:1];
NSString *name = [showData objectAtIndex:2];
NSString *phone = [showData objectAtIndex:3];
NSString *email = [showData objectAtIndex:4];
NSString *price = [showData objectAtIndex:5];
NSString *notes = [showData objectAtIndex:6];
NSLog(@"The Branch: %@", branch);
}
- (IBAction) changeProductText:(NSMutableArray *) arryData{
NSLog(@"array: %@", arryData);
showData = [[NSMutableArray alloc]init];
showData = arryData;
}
Thanks for your help! BR,
Stefan
02-07-2010, 06:21 PM
#4 (permalink )
Registered Member
Join Date: Nov 2009
Location: Helsinki
Posts: 212
In changeProductText you alloc/init showData, but then you replace it with arrayData which I presume is not retained or is released later. What you should do is call
[showData release];
showData = [[NSMutableArray alloc] initWithArray:arrayData];
See if that helps.
02-07-2010, 06:34 PM
#5 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 24
And check, if showData is declared as a NSArray or NSMutableArray.
Regarding the error message, it is declared as NSString, which is wrong.
Furthermore check, if changeProductText is called before viewDidLoad. Otherwise you will also get an error, if the array is undeclared.
02-09-2010, 03:28 PM
#6 (permalink )
Registered Member
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Quote:
Originally Posted by
seb_bue
And check, if showData is declared as a NSArray or NSMutableArray.
Regarding the error message, it is declared as NSString, which is wrong.
Furthermore check, if changeProductText is called before viewDidLoad. Otherwise you will also get an error, if the array is undeclared.
Hi,
I am getting nuts...
Same situation, same result...
I am trying to pass the Variable showData from the ModalViewController to the ShowViewController:
In the ModalViewController I declare:
Code:
controller.showData = [arryData objectAtIndex:indexPath.row];
Where arryData/showData is a NSMutableArray
When I set a Breakpoint I can see that controller.showData is of type NSCFArray (in the ModalViewController (the parent view).
The Breakpoint in the ShowViewController shows that showData is type of NSCFString...
Can please, please, please someone tell my what I am doing wrong?
Thanks for your help and assistance...
ModalViewController:
Code:
ShowViewController *controller = [[ShowViewController alloc] initWithNibName:@"ShowViewController" bundle:nil];
controller.showData = [[NSMutableArray alloc] initWithArray:arryData];
controller.showData = [arryData objectAtIndex:indexPath.row];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
controller = nil;
BR,
Stefan
Last edited by StefanL; 02-09-2010 at 03:35 PM .
02-09-2010, 05:27 PM
#7 (permalink )
Registered Member
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Quote:
Originally Posted by
StefanL
Hi,
I am getting nuts...
Same situation, same result...
I am trying to pass the Variable showData from the ModalViewController to the ShowViewController:
In the ModalViewController I declare:
Code:
controller.showData = [arryData objectAtIndex:indexPath.row];
Where arryData/showData is a NSMutableArray
When I set a Breakpoint I can see that controller.showData is of type NSCFArray (in the ModalViewController (the parent view).
The Breakpoint in the ShowViewController shows that showData is type of NSCFString...
Can please, please, please someone tell my what I am doing wrong?
Thanks for your help and assistance...
ModalViewController:
Code:
ShowViewController *controller = [[ShowViewController alloc] initWithNibName:@"ShowViewController" bundle:nil];
controller.showData = [[NSMutableArray alloc] initWithArray:arryData];
controller.showData = [arryData objectAtIndex:indexPath.row];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
controller = nil;
BR,
Stefan
I am not able to figure it out, but the NSMutableArray will be transformed into a NSCFString in my ShowViewController. As a workaround I am splitting the NSCFString into an Array...
Code:
NSArray *myWords = [showData componentsSeparatedByString:@","];
NSString *test = [myWords objectAtIndex:1];
BR,
Stefan
02-11-2010, 08:37 AM
#8 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 24
I don't understand the following step:
Code:
controller.showData = [[NSMutableArray alloc] initWithArray:arryData];
controller.showData = [arryData objectAtIndex:indexPath.row];
First you set showData to a new array with the content of arryData, then you pick out one element of the array with index "indexPath.row" and assign it to showData.
In my opinion you just have to delete the second line, like this:
Code:
controller.showData = [[NSMutableArray alloc] initWithArray:arryData];
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 965
25 members and 940 guests
anshuk1219 , apatsufas , appalert118 , chits12345 , coding , Dattee , ilmman , iphone.savvy , lavernwatts , LEARN2MAKE , luigi1977 , Marckov85 , Never , Nicoloren , nidie , nizaj , OstinGames2011 , rrlemoine , Shanajisri , supasounds , tasslehawf , TheWebWizz , Thompson22 , violiemay8 , watermelonvodka
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,484
Threads: 89,092
Posts: 380,130
Top Poster: BrianSlick (7,091)
Welcome to our newest member, lavernwatts