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

View Single Post
Old 04-26-2009, 04: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, 200 views)
brandon0104 is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,726
Threads: 89,184
Posts: 380,513
Top Poster: BrianSlick (7,126)
Welcome to our newest member, donbran2
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.