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 06-21-2009, 11:11 PM   #21 (permalink)
appleman
Registered Member
 
Join Date: Feb 2009
Posts: 107
Post

Quote:
Originally Posted by brandon0104 View Post
Probably one of the easiest ways is to read from a property list file (plist). To do this.

Code:
NSString *fileContents = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"plist"];

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

NSMutableArray *items = [categoryDic valueForKey:@"items"];
After you've read your data from your plist file. You can then select a random joke from the items array.

Code:
int randomNumber = arc4random() % [items count];
NSString *joke = [items objectAtIndex:randomNumber];
[someUILabel setText:joke];

Here is an example PLIST file.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>items</key>
	<array>
		<string>joke 1</string>
		<string>joke 2</string>
		<string>joke 3</string>
	</array>
	
</dict>
</plist>
I think that should work, if it doesn't let me know.
Thanks for all the help that you gave out I have a question how can you set

Code:
int randomNumber = arc4random() % [items count];
NSString *joke = [items objectAtIndex:randomNumber];
[someUILabel setText:joke];
to change in sequence on the plist positive or set it to change negative from where is already is?
appleman is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 340
15 members and 325 guests
AgCode, ansonl, beginer2007, bluelobster, ceggert, cordoprod, Eagle11, irishkiwi, Jeremy1026, kindelizaxi, mallmertl, mcgrath3, Rudy, slahteine, vargonian
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,221
Threads: 39,001
Posts: 171,067
Top Poster: smasher (2,569)
Welcome to our newest member, kindelizaxi
Powered by vBadvanced CMPS v3.1.0

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