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

» Advertisements
» Stats
Members: 158,688
Threads: 89,160
Posts: 380,406
Top Poster: BrianSlick (7,110)
Welcome to our newest member, mary3chil
Powered by vBadvanced CMPS v3.1.0

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