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 01-10-2009, 04:45 PM   #4 (permalink)
DenVog
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 500
Default

I kept messing with this. Kinda got it to work, but sometimes get the same response several times in a row (i.e. not seeming very random) and am getting "Warning: local declaration of 'myArray' hides instance variable" messages.

I stuck the following in my Controller.h file
Code:
	NSArray *myArray;
@ property (nonatomic, retain) NSArray *myArray;
and the following in my Controller.m file
Code:
- (IBAction)hello:(id)sender {
	//create the array
	NSArray *myArray= [NSArray arrayWithObjects: @"Yes",@"No",@"Maybe", nil];
	
	//get the length of the array
	int length = [myArray count];
	
	//choose an item - C magic happens here :)
	int chosen = (float)random() * length /RAND_MAX;	
	
	//get that item
	NSString *item = [myArray objectAtIndex: chosen];
	
	//print that item
	helloLabel.text = (@"THe item I picked is: %@", item);
}
hello is a label field that I'm outputting the text to display on screen. Still expect I'm doing something wrong. Help greatly appreciated. Thanks.
DenVog is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,276
Threads: 39,067
Posts: 171,315
Top Poster: smasher (2,575)
Welcome to our newest member, jstewuk
Powered by vBadvanced CMPS v3.1.0

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