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 > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 02-13-2010, 08:07 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default Sum data from several textfields to a label

I'm trying to sum the integers from five UITextFields and post them to a UILabel.

This is the code I have tried. It works to begin with, then it start to mess up! Sometimes it doesent work at all!! Really weird!

int val = [textfield1.text intValue]
val = val+[textfield2.text intValue];
val = val+[textfield3.text intValue];
val = val+[textfield4.text intValue];
val = val+[textfield5.text intValue];

NSString *labelStr = [[NSString alloc] initWithFormat:@"%i", val];

label.text = labelStr;[/b]

Something wrong with the code?? Alternatives maybe? Greatful for all answers!
@@rz is offline   Reply With Quote
Old 02-14-2010, 02:31 AM   #2 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by @@rz View Post
I'm trying to sum the integers from five UITextFields and post them to a UILabel.

This is the code I have tried. It works to begin with, then it start to mess up! Sometimes it doesent work at all!! Really weird!

int val = [textfield1.text intValue]
val = val+[textfield2.text intValue];
val = val+[textfield3.text intValue];
val = val+[textfield4.text intValue];
val = val+[textfield5.text intValue];

NSString *labelStr = [[NSString alloc] initWithFormat:@"%i", val];

label.text = labelStr;[/b]

Something wrong with the code?? Alternatives maybe? Greatful for all answers!
No nothing wrong with the code. You have to be more precise in the description of your problem if you want help. "Starts to mess up"? How?
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 02-14-2010, 04:00 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

Yes you are right. Really bad explenation. The code runs and builds just fine but it don't add right. The number showed on the label is wrong almsot every time!
@@rz is offline   Reply With Quote
Old 02-14-2010, 04:01 AM   #4 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by @@rz View Post
Yes you are right. Really bad explenation. The code runs and builds just fine but it don't add right. The number showed on the label is wrong almsot every time!
Then you'll have to debug line by line.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 02-14-2010, 06:08 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

What do you mean? Please explain.
@@rz is offline   Reply With Quote
Old 02-14-2010, 06:22 AM   #6 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by @@rz View Post
What do you mean? Please explain.
Either yourself or somebody knowledgabe needs to build&debug the app and step through the code to see where the error lies. I can offer to do this for you , but I charge 75 Euros per Hour.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 02-14-2010, 06:26 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

Is there no alternative to my current code to add values between textfields?
@@rz is offline   Reply With Quote
Old 02-14-2010, 06:40 AM   #8 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by @@rz View Post
Is there no alternative to my current code to add values between textfields?
No.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 02-14-2010, 06:57 AM   #9 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Code:
int val = [textfield1.text intValue] + [textfield2.text intValue] + [textfield3.text intValue] + [textfield4.text intValue] + [textfield5.text intValue];
This?
ZunePod is offline   Reply With Quote
Old 02-14-2010, 07:16 AM   #10 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

Same result..
@@rz is offline   Reply With Quote
Old 02-14-2010, 07:22 AM   #11 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

NSLog all of the [textfield1.text intValue] things.
ZunePod is offline   Reply With Quote
Old 02-14-2010, 07:43 AM   #12 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

I'm sorry, but I dont't know how to do that. I would appreciate if you could explaine. Thanks
@@rz is offline   Reply With Quote
Old 02-14-2010, 08:06 AM   #13 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

I'm assuming integers here?

Code:
NSLog(@"%i, %i, %i, %i, %i", [textfield1.text intValue], [textfield2.text intValue], [textfield3.text intValue], [textfield4.text intValue], [textfield5.text intValue]);
ZunePod is offline   Reply With Quote
Old 02-14-2010, 08:16 AM   #14 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

Yes only integers!

Is this a way to diagnose my textfields, or is it a way to calculate?

Last edited by @@rz; 02-14-2010 at 08:20 AM.
@@rz is offline   Reply With Quote
Old 02-14-2010, 08:17 AM   #15 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

No, this is checking what's happening with the numbers, look in your Console to see what the output is, and see if the numbers match what you put into the UITextFields.
ZunePod is offline   Reply With Quote
Old 02-14-2010, 08:42 AM   #16 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

Actual numbers showed in simulator 4 2 2 4 0
2010-02-14 03:34:48.612 Project[72541:207] 2, 0, 0, 4, 0 <<NSLog
2010-02-14 03:34:48.611 Project[72541:207] 6, <<NSLog
@@rz is offline   Reply With Quote
Old 02-14-2010, 08:51 AM   #17 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Quote:
Originally Posted by @@rz View Post
Actual numbers showed in simulator 4 2 2 4 0
2010-02-14 03:34:48.612 Project[72541:207] 2, 0, 0, 4, 0 <<NSLog
2010-02-14 03:34:48.611 Project[72541:207] 6, <<NSLog
So in the textfield you put 4 2 2 4 0?

I think your linking something wrong, or you have a - somewhere.
ZunePod is offline   Reply With Quote
Old 02-14-2010, 09:29 AM   #18 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 12
Default

Thank you for your time. I solved it by using a if formula instead.
@@rz is offline   Reply With Quote
Reply

Bookmarks

Tags
adding data, uilabel, 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: 262
18 members and 244 guests
14DEV, @sandris, ADY, ArtieFufkin10, ckgni, Dani77, HemiMG, IphoneSdk, jakerocheleau, JasonR, MACralik, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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