【发布时间】:2015-04-11 07:57:33
【问题描述】:
我已将 iOS 版本更新到 8.2,但现在遇到了 UIDatePicker 和 UITextfield 键盘隐藏的一些问题。在 iOS 8 中,不支持 UIActionsheet,因此我更改了代码以显示日期选择器,但现在选择器打开时键盘没有隐藏。 这是我的日期选择器代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField resignFirstResponder];
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,self.view.bounds.size.width, self.view.bounds.size.height)];
[myView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]];
[self.view addSubview:myView];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 244, self.view.bounds.size.width, 44)];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissActionSheet)];
toolbar.items = @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], done];
toolbar.barStyle = UIBarStyleBlackOpaque;
[self.view addSubview:toolbar];
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 200, 0, 0)];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.hidden = NO;
datePicker.date = [NSDate date];
datePicker.maximumDate = [NSDate date];
[datePicker addTarget:self
action:@selector(LabelChange:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
}
但键盘没有隐藏。
【问题讨论】:
-
延迟一段时间后调用选择器创建方法(时间与键盘隐藏相同)
标签: ios objective-c iphone uidatepicker ios8.2