Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-07-2010, 03:53 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default 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.
StefanL is offline   Reply With Quote
Old 02-07-2010, 05:01 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 24
Default

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 View Post
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
seb_bue is offline   Reply With Quote
Old 02-07-2010, 05:21 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default

Quote:
Originally Posted by seb_bue View Post
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
StefanL is offline   Reply With Quote
Old 02-07-2010, 06:21 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 212
Default

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.
fiftysixty is offline   Reply With Quote
Old 02-07-2010, 06:34 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 24
Default

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.
seb_bue is offline   Reply With Quote
Old 02-09-2010, 03:28 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default

Quote:
Originally Posted by seb_bue View Post
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.
StefanL is offline   Reply With Quote
Old 02-09-2010, 05:27 PM   #7 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default

Quote:
Originally Posted by StefanL View Post
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
StefanL is offline   Reply With Quote
Old 02-11-2010, 08:37 AM   #8 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 24
Default

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];
seb_bue is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,484
Threads: 89,092
Posts: 380,130
Top Poster: BrianSlick (7,091)
Welcome to our newest member, lavernwatts
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:53 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0