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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 07-08-2010, 03:53 PM   #1 (permalink)
Registered Member
 
macisthegeek's Avatar
 
Join Date: Feb 2010
Location: Canada, Alberta
Posts: 26
macisthegeek is on a distinguished road
Default Loading group in plist to an array

Hello everybody,

I'm trying to load some data form a certain group in a plist to an array which will then be displayed in a tableview.

Again Im trying to just load the childs form the first group in the plist to the array.

Here is my code that im using:

Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *booksFile = [NSString stringWithFormat:@"%@/Data.plist",documentsDirectory];
	NSMutableArray* dataPlistArray = [[NSMutableArray alloc] initWithContentsOfFile:booksFile];
	NSMutableArray* mutableArray = [[NSMutableArray alloc] init];
	[dataPlistArray objectAtIndex:0];
	for(NSDictionary* dict in dataPlistArray)
	{
		data* book = [[data alloc] init];
		book.title = [dict objectForKey:@"title"];
		book.description = [dict objectForKey:@"description"];
		[mutableArray insertObject:book atIndex:0];
		[book release];
	}
	
	mainData = [[NSArray alloc] initWithArray:mutableArray];
	[mutableArray release];
	[dataPlistArray release];
	
	[table reloadData];
Here is my plist:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<<array>
	<array>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
	</array>
	<array>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
		<dict>
			<key>description</key>
			<string>disc</string>
			<key>title</key>
			<string>title</string>
		</dict>
	</array>
</array>
But it doesn't work, the app crashes with:
Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFArray objectForKey:]: unrecognized selector sent to instance 0x556bf20
Thanks for your help

Last edited by macisthegeek; 07-08-2010 at 11:22 PM.
macisthegeek is offline   Reply With Quote
Reply

Bookmarks

Tags
plist to an array

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
» Online Users: 337
13 members and 324 guests
akphyo, cgokey, EXOPTENDAELAX, GHuebner, guusleijsten, Mirotion22, ohmniac, Paul Slocum, PavelSea, Pudding, SLIC, Sloshmonster, Sonuye857
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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