MOBILE

iPhone Application Development : Making Multivalue Choices with Pickers - Using Date Pickers (part 2) - Adding a Date Picker

2/25/2011 9:51:53 PM

Adding a Date Picker

Open the empty view in the DateCalcViewController.xib file, and then open the object Library (Tools, Library). Find the date picker (UIDatePicker) object and drag it into the view. You’ll notice immediately that, unlike other UI elements we’ve used, the date picker takes up a lot of screen real estate.

Position the date picker at the top of the screen, as shown in Figure 2. We’ll be displaying the date calculations below it.

Figure 2. Date pickers use quite a bit of screen space.

By default, the date picker displays a date and time, as demonstrated in our current view. As with other controls, the Attributes Inspector can customize how the date picker appears to the user.

Setting the Date Picker Attributes

Choose the date picker within the view, and then open the Attributes Inspector (Command+1), shown in Figure 3.

Figure 3. Configure the appearance of the date picker in the Attributes Inspector.


The picker can be configured to display in one of four different modes:

Date & Time: Shows options for choosing both a date and a time

Time: Shows only times

Date: Shows only dates

Timer: Displays a clock-like interface for choosing a duration

You can also set the locale for the picker, which determines the ordering of the different components; set the default date/time that is displayed; and set date/time constraints to help limit the user’s choices.

For this project, leave the default settings as they are. We want the user to choose a date and a time that we’ll use in our calculations.

By the Way

The Date attribute is automatically set to the date and time when you add the control to the view.


Connecting to the Action

When the user interacts with the date picker, we want the showDate action method to be called. To create this connection, select the picker, and then open the Connections Inspector (Command+2).

Click and drag from the circle beside Value Changed to the File’s Owner icon. When you release the mouse button, you’ll be prompted for the action. Choose showDate, as demonstrated in Figure 4. This should be almost a reflex action by now!

Figure 4. Connect to the showDate action.

Did you Know?

We’ve been making a point of using the Connections Inspector to create connections from objects that support many different events. This is always the safest way to know what connections you’re creating, but it isn’t the fastest. The picker (along with switches and segmented controls) will default to making connections using the Value Changed event if you Control-drag from the element to the File’s Owner icon. You can use this shortcut if you feel comfortable with the process.

Other  
  •  iPhone Application Development : Making Multivalue Choices with Pickers - Understanding Pickers
  •  Sync Your iPad with iTunes : Troubleshooting iTunes and the Sync
  •  Sync Your iPad with iTunes : Manually Transferring Music, Movies, Podcasts, and More on Your iPad (Drag-and-Drop Method)
  •  Windows Phone 7 Development : Internationalization - Using Resource Files to Localize Content
  •  Windows Phone 7 Development : Internationalization - Storing and Retrieving Current Culture Settings
  •  Mobile Application Security : WebOS Security - Development and Security Testing
  •  Mobile Application Security : WebOS Security - Introduction to the Platform
  •  iPhone Application Development : Getting the User’s Attention - Using Alert Sounds and Vibrations
  •  iPhone Application Development : Getting the User’s Attention - Using Action Sheets
  •  jQuery 1.3 : Modifying table appearance (part 4) - Filtering
  •  jQuery 1.3 : Modifying table appearance (part 3) - Collapsing and expanding sections
  •  jQuery 1.3 : Modifying table appearance (part 2) - Tooltips
  •  jQuery 1.3 : Modifying table appearance (part 1) - Row highlighting
  •  Windows Phone 7 Development : Using Culture Settings with ToString to Display Dates, Times, and Text
  •  Mobile Application Security : SymbianOS Security - Persistent Data Storage
  •  Mobile Application Security : SymbianOS Security - Interprocess Communication
  •  Mobile Application Security : SymbianOS Security - Permissions and User Controls
  •  Windows Phone 7 Development : Building a Trial Application (part 3) - Verifying Trial and Full Mode & Adding Finishing Touches
  •  Windows Phone 7 Development : Building a Trial Application (part 2) - Connecting to a Web Service & Adding Page-to-Page Navigation
  •  Windows Phone 7 Development : Building a Trial Application (part 1) - Building the User Interface
  •  
    Most View
    Samsung Galaxy Note 800 - A Fresh Challenge
    Adobe Flash Professional CS5 : Publishing Flash Documents (part 4) - Alternative Publishing Options
    ViewSonic VSD220 - Turns Android Into A Desktop Computer
    Transforming and Animating Content in Silverlight
    My ipad : Presentations with Keynote - Organizing Slides
    Intel In Flux: Are We Heading To A Socket-Less Future? (Part 1)
    AMD A10-5800K - Trinity on the Desktop
    Tech Preview 2013 (Part 2) - Portable PCS, Mortherboards
    Using the Dynamic Keyword in C# 4.0
    Intel’s Next Unit Of Computing Review - The Future Desktop Or Another Nettop? (Part 4)
    Top 10
    Windows Phone 8 In-Depth Review (Part 6)
    Windows Phone 8 In-Depth Review (Part 5)
    Windows Phone 8 In-Depth Review (Part 4)
    Windows Phone 8 In-Depth Review (Part 3)
    Windows Phone 8 In-Depth Review (Part 2)
    Windows Phone 8 In-Depth Review (Part 1)
    Xiaomi Phone 2 - High-End Specifications In A Surprisingly Cheap Package (Part 5)
    Xiaomi Phone 2 - High-End Specifications In A Surprisingly Cheap Package (Part 4)
    Xiaomi Phone 2 - High-End Specifications In A Surprisingly Cheap Package (Part 3)
    Xiaomi Phone 2 - High-End Specifications In A Surprisingly Cheap Package (Part 2)