.h
@interface CustomKeyboardAppDelegate : NSObject <UIApplicationDelegate> {
...
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UIToolbar *accessoryView;
@property (nonatomic, retain) IBOutlet UIDatePicker *customInput;
- (IBAction)dateChanged:(id)sender;
- (IBAction)doneEditing:(id)sender;
@end
.m
@implementation CustomKeyboardAppDelegate
@synthesize window=_window;
@synthesize textField = _textField;
@synthesize accessoryView = _accessoryView;
@synthesize customInput = _customInput;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.textField.inputView = self.customInput;
self.textField.inputAccessoryView = self.accessoryView;
...
}
...
- (IBAction)dateChanged:(id)sender {
UIDatePicker *picker = (UIDatePicker *)sender;
self.textField.text = [NSString stringWithFormat:@"%@", picker.date];
}
- (IBAction)doneEditing:(id)sender {
[self.textField resignFirstResponder];
}
@end
Second way
- (void)textFieldDidBeginEditing:(UITextField *)sender
{
sender.delegate = self;
if([sender isEqual:dateFieldText])
{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithTitle:@"Save Date"
style:UIBarButtonItemStyleDone
target:self
action:@selector(datePicker)];
self.navigationItem.rightBarButtonItem = doneButton;
}
else{
UIBarButtonItem *submitButton = [[UIBarButtonItem alloc]
initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self
action:@selector(datePicker)];
self.navigationItem.rightBarButtonItem = submitButton;
}
}
-(IBAction)datePicker
{
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
[datePicker addTarget:self action:@selector(saveDate) forControlEvents:UIControlEventValueChanged];
[self.dateFieldText setInputView:datePicker];
}
No comments:
Post a Comment
Comment