Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-16-2010, 11:50 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 38
loddy1234 is on a distinguished road
Unhappy Random Number

I am trying to make an app that generates a random nuber between 0 and a chosen number. The idea is the user types a number into a text box and presses the generate button and a label is changed to the random number.
Here my code for the button press
-(IBAction)button1Press: (id) sender{

NSString *input;
int randomNumber;

input = targetNumber.text;

int Number = [input intValue];

randomNumber = (random() % Number) + 1;
choice.text =(@"%d", randomNumber); //Getting error here
}

targetNumber is defined in the .h file as a UITextField <--- Is this correct?
choice is defined in the .h file as a UILabel

I am gettin a warning on the last line saying "passing argument 1 of 'setText:' makes pointer from integer without a cast".
When i type a number into the text box and press generate, the app crashes.
any ideas why I am getting the warning?
example code appreciated as I am new to Objective C.
Thanks in advance
loddy1234 is offline   Reply With Quote
Old 10-16-2010, 11:56 AM   #2 (permalink)
iPhone Developer
 
Join Date: Aug 2009
Posts: 64
losingSkillz is on a distinguished road
Default

use
Code:
choice.text = [NSString stringWithFormat:@"%d", Number];
hope that helps
__________________
If I helped you in any way, please help me by checking out my apps:

iPower Your Device --- Charge Up your device!

(FREE)


losingSkillz is offline   Reply With Quote
Old 10-16-2010, 12:03 PM   #3 (permalink)
"Sorry, but I dont know."
 
Join Date: Dec 2009
Location: Switzerland (CH)
Age: 16
Posts: 213
mavrick3 is on a distinguished road
Default

I would use this:

Code:
- (IBAction)buttonClicked {

int randomNumber = (arc4random() % [input intValue]) + 1;
choice.text = [NSString stringWithFormat:@"%i", randomNumber];

}
mavrick3 is offline   Reply With Quote
Old 10-16-2010, 12:14 PM   #4 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 38
loddy1234 is on a distinguished road
Smile

Thanks it works now
loddy1234 is offline   Reply With Quote
Reply

Bookmarks

Tags
choice, generate, integer, random, uitextfield

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 338
8 members and 330 guests
Desert Diva, dre, hain, HemiMG, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0