Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

2. Implementing Controllers and Views > 2.4. Picking the Date and Time with UID...

2.4. Picking the Date and Time with UIDatePicker

Problem

You want to allow the users of your app to select a date and time using an intuitive and ready-made user interface.

Solution

Use the UIDatePicker class.

Discussion

UIDatePicker is very similar to the UIPickerView class. The date picker is in fact a prepopulated picker view. A good example of the date picker control is in the Calendar app on the iPhone (Figure 2-14).

A date picker shown at the bottom of the screen

Figure 2-14. A date picker shown at the bottom of the screen

Let’s get started by first declaring a property of type UIDatePicker and then allocating and initializing this property and adding it to the view of our view controller:

#import <UIKit/UIKit.h>

@interface Picking_Date_and_Time_with_UIDatePickerViewController
           : UIViewController

@property (nonatomic, strong) UIDatePicker *myDatePicker;

@end

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial