Home > Tutorials Home > Ios > DateTimePicker in UIActionsheet

DateTimePicker in UIActionsheet

Published on October 17, 2019 8:28:19 PM

UIActionSheet Example

We are an online tutoring company that has laid its foundation in utilizing Multiple Intelligence methodology to understand specific needs and learning styles of a student.This is the ButtonPressed example. In this example we will see how to load another view after pressing button. So let see how it will worked. Another Buttonpress reference you can find out from here ButtonView in iPhone.So that we patch a particular student to a tutor having a compatible teaching style. We have devised a smart online tutoring system to give you measurable results.Schools, cramped with students, fail to give your child the edge, the motivation and the right teacher guidance to help him find the true potential. We at make sure that your child gets the perfect learning environment to outperform.

Step 1 : Open the XCode and create a new Single View Based Application template. Give the application name "UIActionSheet Example". Copy this Code to the ViewController.h and hook up the properties with appropriate control.

#import <UIKit/UIKit.h>

@interface AbhishekViewController : UIViewController<UIActionSheetDelegate>
@property (retain, nonatomic) IBOutlet UILabel *lelMessage;
- (IBAction)loadDatePicker:(id)sender;
@property (nonatomic,retain) UIDatePicker *datePicker;

Step 2 : Copy the Following Code into your ViewController.m File.

#import "AbhishekViewController.h"

@implementation AbhishekViewController

@synthesize lelMessage;
@synthesize datePicker;
- (IBAction)loadDatePicker:(id)sender
    NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
	UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"%@%@", title, NSLocalizedString(@"SelectDateKey", @"")] delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Okey",nil, nil];
	[sheet showInView:self.view];
    datePicker = [[[UIDatePicker alloc] init] autorelease];
    datePicker.datePickerMode = UIDatePickerModeDate;
    [datePicker setDate:[NSDate date]];
    [sheet addSubview:datePicker];

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    if (buttonIndex == 0)
		NSDate *date =;
		NSDateFormatter *format = [[NSDateFormatter alloc]init];
		[format setDateFormat:@"dd-MMMM-yyyy"];
		NSString *fullDate = [format stringFromDate:date];
		[lelMessage setText:fullDate];