IOS 点击TextField弹出DatePicker
时间:10月27日
用textfield的inputview和inputAccessoryView两个属性。创建datePicker,赋值给两个textfield的inputview属性。创建toolbar,包含一个Done按钮,赋值给inputAccessoryView属性。你需要用这个Done来退出inputview。 Done的事件处理: if ( [textField isFirstResponder] ) { ????[textField resignFirstResponder]; } Example @interface CustomKeyboardAppDelegate : NSObject <</span>UIApplicationDelegate> { ... @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITextField *textField; @property (nonatomic, retain) IBOutlet UIToolbar *toolbarInput; @property (nonatomic, retain) IBOutlet UIDatePicker *datePickInput; - (IBAction)dateChanged:(id)sender; - (IBAction)doneEditing:(id)sender; @end 在XIB文件中,拖出 一个UIToolbar和一个UIDatePicker,但不要附加到View中(拖到视图外面)。适当的连接Outlets。dateChanged:响应datepicker的ValueChanges,doneEditing:被ToolBar中的Done按钮点击时调用(Connection->Sent Actions->selectors)。以下是实现: @implementation CustomKeyboardAppDelegate @synthesize window=_window; @synthesize textField = _textField; @synthesize toolbarInput = _toolbarInput; @synthesize datePickInput = _datePickInput; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ????self.textField.inputView = self.datePickInput; ????self.textField.inputAccessoryView = self.toolbarInput; ????... ??? } ... - (IBAction)dateChanged:(id)sender { ????UIDatePicker *picker = (UIDatePicker *)sender; ????self.textField.text = [NSString stringWithFormat:@"%@", picker.date]; } - (IBAction)doneEditing:(id)sender { ????[self.textField resignFirstResponder]; } @end
最新动态
大家感兴趣的内容
关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿
严禁网站镜像,否则追究法律责任 CopyRight © 2015-2018 诺心网络 All Rights Reserved.
地址:杭州拱墅区祥园路38号浙报理想祥园创意园东区A319
电话:18958065710 微信:Evtailun 邮箱:476565345@qq.com
网站备案号:浙ICP备15017827号-1