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 Tutorials

Reply
 
LinkBack Thread Tools Display Modes
Old 03-08-2009, 11:40 PM   #1 (permalink)
Tutorial Author
 
Steaps's Avatar
 
Join Date: Oct 2008
Location: Ontario, Canada
Posts: 466
Default [Tutorial] UIPickerView: The Basics (Basic Tip Calculator)

So today i was bored and learned how to use UIPickerViews. Next someone asked me how to use them, so i decided to make a tutorial on them. The tutorial can be found on my blog at: Steaps’ Blog! :: Random :: Tutorial: UIPickerView Basics

The tutorial uses an NSMutableArray to set the rows of the UIPickerView, and some logical math to do the tip calculating.

If you notice something wrong, please post a comment or e-mail me about it. Thanks .

Last edited by Steaps; 03-09-2009 at 09:39 PM.
Steaps is offline   Reply With Quote
Old 03-09-2009, 04:07 AM   #2 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

nice work man! thanks
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Old 03-09-2009, 08:49 PM   #3 (permalink)
Tutorial Author
 
Steaps's Avatar
 
Join Date: Oct 2008
Location: Ontario, Canada
Posts: 466
Default

Quote:
Originally Posted by Bertrand21 View Post
nice work man! thanks
No problem! . I feel proud that i did something useful now .

EDIT: I just updated the video, should be easier to see now.

Last edited by Steaps; 03-09-2009 at 09:40 PM.
Steaps is offline   Reply With Quote
Old 08-17-2009, 10:15 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 140
Default

great tutorial!! I was wondering if there was a way to make a "custom" picker in the sense of having the picker be pink instead of gray. And if there is anything else you can do to customize it.
ybrikeeg is offline   Reply With Quote
Old 08-18-2009, 05:53 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
Default

Off topic i know, but whats the winterboard theme called that you used in your cracked screen app?
Hackintosh Dev is offline   Reply With Quote
Old 08-18-2009, 11:28 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 140
Default

Quote:
Originally Posted by Hackintosh Dev View Post
Off topic i know, but whats the winterboard theme called that you used in your cracked screen app?
From my YouTube video?
ybrikeeg is offline   Reply With Quote
Old 08-19-2009, 06:48 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
Default

From Steaps' video of the cracked screen simulation:

Steaps’ Blog! :: Random :: [Release] Cracked Screen – Jailbroken Devices Only

This theme is amazing!
Hackintosh Dev is offline   Reply With Quote
Old 08-24-2009, 04:11 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Calgary, AB
Posts: 64
Default

Quote:
Originally Posted by ybrikeeg View Post
great tutorial!! I was wondering if there was a way to make a "custom" picker in the sense of having the picker be pink instead of gray. And if there is anything else you can do to customize it.
Took some time, but I figured out how to add billTotal and tipAmount.

- Add a Label to your .xib file (delete the text "Label")
- Add (to your .h file) IBOutlet UILabel *totalAmount;
- In your .m file (below where the PickerView calculates the numbers) add this below "tipAmount.text....bla bla bla"
totalAmount.text = [[NSString stringWithFormat:@"Total: $%.2f", (tipTotal + [billTotal.text floatValue])];

That should be it. Now when you enter a bill amount and scroll the pickerview to the percentage you want to tip it will display the "Tip Amount" (as in the tutorial)... and, it will add the bill amount, tip amount and give you a total amount. Kinda confusing, but it works.
voiperguy is offline   Reply With Quote
Old 08-27-2009, 06:33 PM   #9 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Calgary, AB
Posts: 64
Default

Con't of "TipCalc"

Tips do not usually include the tax so I've added a little something to this tutorial (originally by Steaps)

In your .h file:

IBOutlet UITextField *taxTotal;

In your .xib file, include a Text Field from your Library. Add a Label beside it, "Tax:"

In Connections Inspector, connect the text field "taxTotal" (you know what I mean)

In your .m file:

in the voidDidLoad, under billTotal.delegate = self;
add this: taxTotal.delegate = self;
(this will remove the text field after pressing Done)

in the (void)pickerView, if you followed Steaps tutorial you will find a line looking like this: float tipTotal = [(billTotal.text....bla bla bla)

Change this line to:
float tipTotal = ([billTotal.text floatValue] - [taxTotal.text floatValue]) * tipSelected;

Build & Go

If you made your connections properly then when you run the tutorial, you should see the original Bill Amount (text field), your new Tax (text field) and the rest of it...the pickerView and Tip Amount label.

When you enter your Bill...say $100...and enter a tax amount of i.e. $10, then scroll to 10% tip... your new "Tip Amount" is $9.00

You might want to make the "Tip Amount" label (in the .xib) a little smaller to fit the other results.

I'm going to make future additions to this as I learn...if you're interested.
voiperguy is offline   Reply With Quote
Old 08-28-2009, 09:54 AM   #10 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Calgary, AB
Posts: 64
Default

Ok, now lets Split the bill.

in your .h file, add 2 more outlets:

IBOutlet UITextField * splitPerson;
IBOutlet UILabel * splitAmount;

In your .xib file, add another Text Field and a label "Split" to the left of your new field. Add another Label for the splitAmount.

Make your connections.

In your .m file, in the (void)viewDidLoad section, add this line:
splitPerson.delegate = self;
(again, this will release the keyboard when pressing Done).

within the (void)pickerViewUIPickerView *)...if you followed the previous post for this topic, you will have a line... totalAmount.text = [NSString...blablabla

under that line, enter this:

float splitTotal = (([billTotal.text floatValue] + [taxTotal.text floatValue] + tipTotal) / [splitPerson.text floatValue]);
splitAmount.text = [NSString stringWithFormat:@"$%.2f", splitTotal];

Build & Go.

Now you should have your TipCalc fully operational. Enter your bill, tax and how many people to split...scroll the % you want...and presto... you now have all your 'labels' filled with the results.

This isn't full proof. If you put a "0" in for the Split, in your splitAmount label, you will see the result "#inf". The coding needs an "if/else" statement, but I'm not that Xcode savvy yet

This was the "Easy" way of doing the split. I would really appreciate if someone could expand on this and show us how to not use a UITextField to input the Split #, but use the PickerView (with 2 scrolling areas), left side for the tip % and the right side for the splitPerson 1-2-3-4..10, etc.
voiperguy is offline   Reply With Quote
Old 08-31-2009, 04:12 PM   #11 (permalink)
iOS Developer
 
chaseacton's Avatar
 
Join Date: Feb 2009
Location: United States
Posts: 532
Send a message via AIM to chaseacton Send a message via Skype™ to chaseacton
Default

Thank you so much!!! + Rep for you.

I do have one question though. How could i make this have custom tip percents though. I mean instead of 1, 2, 3, 4, etc. I want 1, 5, 10 ,15, etc.

Thanks in advanced,
Chase
__________________
Freelance Inquiries:
www.chaseacton.com/services

Apps:
chaseacton is offline   Reply With Quote
Old 09-08-2009, 02:38 PM   #12 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 162
Default

Thank you very much for this nice tutorial. Comes in very handy
web20devxer is offline   Reply With Quote
Old 09-13-2009, 07:19 PM   #13 (permalink)
Tutorial Author
 
Steaps's Avatar
 
Join Date: Oct 2008
Location: Ontario, Canada
Posts: 466
Default

Noo problem .
Steaps is offline   Reply With Quote
Old 08-20-2010, 01:23 PM   #14 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Leeds, UK
Age: 26
Posts: 45
Default

I just wanted to say thanks. This is by far the most helpful tutorial on UIPickerViews I have been able to find!
zeolite is offline   Reply With Quote
Old 08-23-2010, 01:05 PM   #15 (permalink)
I will be a billionaire.
 
IphoneSdk's Avatar
 
Join Date: Sep 2009
Location: Scarborough, United Kingdom
Age: 16
Posts: 1,292
Default

Awesome Tutorial!
__________________
iOS Apps | Website | Twitter | Facebook
IphoneSdk is offline   Reply With Quote
Old 08-24-2010, 02:49 PM   #16 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 62
Default

really great work...
farazhaider88 is offline   Reply With Quote
Old 11-28-2010, 08:17 PM   #17 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 13
Default

thanks for this. It helped me greatly.

Only suggestion I can think of is to add a blurb about the protocols that you supported. As a beginner, I didn't know what the thing was all about...but then I found it elsewhere.

This really helped me though!
kraftyDevil 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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 238
14 members and 224 guests
ADY, AragornSG, Dani77, Dattee, Duncan C, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
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 03:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0