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.

  •  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
    Top 10
    ADO.NET Programming : Microsoft SQL Server CE (part 5) - Querying Schema Information
    ADO.NET Programming : Microsoft SQL Server CE (part 4) - Updating a SQL Server CE Database, The SqlCeDataAdapter Class
    ADO.NET Programming : Microsoft SQL Server CE (part 3) - Retrieving and Displaying Data
    ADO.NET Programming : Microsoft SQL Server CE (part 2) - SQL Server CE Query Analyzer, Creating a SQL Server CE Database, Populating a SQL Server CE Database
    ADO.NET Programming : Microsoft SQL Server CE (part 1) - SQL Server CE Files, SQL Server CE Syntax
    Silverlight Recipes : Controls - Displaying Information in a Pop-up
    Silverlight Recipes : Controls - Customizing the Default ListBoxItem UI
    Windows 7 : Zero Touch Installations - Monitoring Deployment Progress
    Windows 7 : Zero Touch Installations - Deploying Windows 7 (part 3) - Performing the Zero Touch Installation
    Windows 7 : Zero Touch Installations - Deploying Windows 7 (part 2) - Edit the Deployment Task Sequence
    Most View
    Windows 8’s Anatomy (Part 2)
    Cocoa Fundamentals
    HP Pavilion G7 - Affordable Desktop Replacement
    Intel Ivy Bridge : Core i5-3570k and Core i7-3770K (part 2)
    Buying Guide: Memory Kit (Part 1) - Centon Advanced DDR3-2133 16GB (CMP2133PC4096.01K4)
    Outlining AD DS Changes in Windows Server 2008 R2 (part 2) - Implementing Multiple Password Policies per Domain
    Building Android Apps : Detecting Browsers with WURFL
    Silverlight JavaScript Reference
    SQL Server 2008 : Developing with LINQ to SQL (part 2) - Uncovering LINQ to SQL with Linqpad
    Amazing: Mimicry Of Nature… By Tech (Part 1) - Innovation and copycats
    The New iPad
    The Future Of Apple: Chip Off The Block (Part 9)
    Macbook Air vs. Ultrabook Platform (Part 2)
    Kingston HyperX 3K SSD : SSD For The Budget Conscious
    Windows 7 : Configuring Network Connectivity - Understanding Networking
    Smart Shopping: Sleighful Of Bargain-Tracking Apps
    Google vs. Apple vs. Microsoft
    SharePoint 2007 : Use the Datasheet View to Add, Edit, or Delete Items and Files
    AMD Radeon HD 7870 - Game-Breaking Power
    A Partnership Fizzles