Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-26-2009, 03:01 PM   #4 (permalink)
brandon0104
Registered Member
iPhone Dev SDK Supporter
 
Join Date: Oct 2008
Posts: 10
Default

Just create a new PLIST in Xcode. File > New File > Other > Property List File. Name it anything you would like, just change :@"filename" to the name of your file, NOT including ".plist".

Once you begin to edit you will see your Root which is your dictionary (<dict>) . Add as many arrays as you would like.

Change [categoryDic valueForKey:@"items"]; to whatever you name your Array. For example

Code:
NSMutableArray *items = [categoryDic valueForKey:@"sillyjokes"];
If the name of your array is "sillyjokes". ' I've uploaded an example PLIST file.

You insert the code I posted before in the action of your button. since the NSString *fileContents is used multiple times its easier to place it in your header file. Same with UILabel *someLabel;

Code:
- (IBAction)randomSillyJoke:(id)sender {
fileContents = [[NSBundle mainBundle] pathForResource:@"sillyjokes" ofType:@"plist"];

NSDictionary *sillyJokes = [[NSDictionary alloc] initWithContentsOfFile:fileContents];

NSMutableArray *sillyjokes = [categoryDic valueForKey:@"jokes"];

int randomNumber = arc4random() % [items count];
joke = [sillyJokes objectAtIndex:randomNumber];
[someUILabel setText:joke];
}
- (IBAction)randomDirtyJoke:(id)sender {
fileContents = [[NSBundle mainBundle] pathForResource:@"dirtyjokes" ofType:@"plist"];

NSDictionary *dirtyJokes = [[NSDictionary alloc] initWithContentsOfFile:fileContents];

NSMutableArray *dirtyjokes = [categoryDic valueForKey:@"jokes"];

int randomNumber = arc4random() % [items count];
joke = [dirtyJokes objectAtIndex:randomNumber];
[someUILabel setText:joke];
}



Hope this helps
Attached Files
File Type: zip sillyjokes.zip (722 Bytes, 111 views)
brandon0104 is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 234
11 members and 223 guests
Ajameel, alexz1, Bertrand21, DonomaGames, Erle, flamingliquid, jyu, Karts9, Oliver Drobnik, SirGeraint, smilespray
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,279
Threads: 39,072
Posts: 171,336
Top Poster: smasher (2,575)
Welcome to our newest member, yogen81
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:56 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.