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 Tutorials > Tutorial Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 08-31-2008, 12:53 PM   #1 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 2
bones237 is on a distinguished road
Default Currency Converter

This tutorial from Nitrex88 was awesome... You know that feeling when you've been searching all day on how to do something and then you find something that explains exactly what u were trying to do? Awesome, right? Well that's what it was like when I find this one. I'm fairly new to developing for mac OS and iphone (only 2 months in) so this was great.
I do have one question that maybe somebody can help me with.
In Nitrex's tut, he was using text fields to enter float values and then perform a calculation between them.
For what I am using this for, I changed the float values to integer values. What should I do if I don't want a certain value to exceed a number. For ex. if the user enters a number greater than 4 into one of the text fields, that text fields integer value would be equal to 4? This is what I tried:

Code:
if([aTextField.text intValue] > 4){
		aTextField.text = 4;
	}
I put this code right before the line of code that performs the calculation but it didn't work. It actually compiles but when a number greater than 4 is entered in "aTextField", my app freezes.

Also, how do i perform rounds. If the result of my calculation needs to be rounded up or rounded down, how can I do that? Do I need to change my float values back to integer values and then perform some code, right?
Any help would be greatly appreciated
bones237 is offline   Reply With Quote
Old 08-31-2008, 01:34 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 2
Cibetik is on a distinguished road
Default

textfield.text has to be a string value, so you cannot put number as text property. You can do
NSNumber *intNumber=[NSNumber numberWithInt:4];
textField.text=[intNumber stringValue];
Cibetik is offline   Reply With Quote
Old 08-31-2008, 02:33 PM   #3 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 2
bones237 is on a distinguished road
Default

Quote:
Originally Posted by Cibetik View Post
textfield.text has to be a string value, so you cannot put number as text property. You can do
NSNumber *intNumber=[NSNumber numberWithInt:4];
textField.text=[intNumber stringValue];
Hey thanks for the reply. I just was about to edit my post when I saw yours. I figured out how to do it but I came up with a different way than yours. This is what i did:

Code:
if([textField.text intValue] > 4){
    textField.text = [NSString stringWithString: @"4"];
}
I was playing around with the code until i got this. Which way is the more proper way to do it ( in terms of correct way to program)? Mine or Yours?
Either way, they both do the same thing: When a user enters say 20 into the text field, once i hit my "calculate" button the text field value is assigned a 4, which is what i want, but the text field also displays that 4 that it changed to. Is there any way to change the value to 4 like it does but also keep the value that is displayed in the text field to 20, or whatever they entered.
The reason for this is once the user enters 20 then hits calculate, they may think they messed up cuz they'll see the text field change to 4 even tho they entered 20. I want to keep what they entered in the display but behind the scenes change the value to 4. Is this possible?
bones237 is offline   Reply With Quote
Old 09-01-2008, 02:35 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 2
Cibetik is on a distinguished road
Default

I´m not sure, what you want to do, but one option is not assign 4 to textfield.text but create new variable (e.g. integer) and assign textfield.text value to this integer:
Code:
//for example input was 20 so
NSInteger integer=[textfield.text intValue];
and then use value integer so:
Code:
integer=4;
textfield will still show 20 and you will use value integer for your code

Your code i
Code:
f([textField.text intValue] > 4){
    textField.text = [NSString stringWithString: @"4"];
}
is better for your situation, my is better, when you need do some operation with number.
Cibetik is offline   Reply With Quote
Old 09-23-2008, 10:43 AM   #5 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
roberthuttinger is on a distinguished road
Default

I thought this would help as well. Ive been trying this for 4 hours til I finally found this simple solution. the basics are good to learn I hear!
Quote:
oppnumber=[[[mainDelegate.personArray objectAtIndex:1] lastName] intValue];
cheers.rob
roberthuttinger is offline   Reply With Quote
Reply

Bookmarks

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: 448
17 members and 431 guests
Dj_kades, givensur, iekei, IOOIOIO, IphoneSdk, jeroenkeij, john love, karatebasker, mediaspree, peterwilli, pipposanta, Punkjumper, QuantumDoja, SLIC, Sloshmonster, sojourner, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,959
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

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