我添加UITextView
了一个子视图UIAlertView
,我添加UIToolBar
了一个完成按钮(使用UIBarButtonItem
)inputAccessoryView
以允许用户退出键盘`。它在 iOS6.0 中运行良好。而不是在iOS5.0 中。
我已经断点并尽我所能检查,为了重新确认我自己,我制作了一个示例项目并在两个iOS版本中检查了相同的问题,问题是一样的。
这是代码,这让我很困惑,
-(UIToolbar *)accessoryView
{
if (!accessoryView) {
accessoryView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44.0)];
UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(hideKeyBoard)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
accessoryView.items = [NSArray arrayWithObjects:flexibleSpace,btn, nil];
[accessoryView setTintColor:[[UIColor blackColor]colorWithAlphaComponent:0.5]];
}
return accessoryView;
}
-(IBAction) showAlertWithTextView: (id) sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 50, 320, 200)];
alert.title = nil;
alert.message = nil;
alert.delegate = self;
//textview I've added in .h file
textView = [[UITextView alloc] initWithFrame:alert.bounds];
textView.text = @"This is a UITextView";
textView.keyboardAppearance = UIKeyboardAppearanceAlert;
textView.editable = YES;
textView.inputAccessoryView = [self accessoryView];
[alert addSubview:textView];
[alert show];
}
- (void)hideKeyBoard {
[textview resignFirstResponder];
//[self.view endEditing:YES]; //this is also not worked
}
这是我正在执行的步骤列表,
- 使用 Textview 显示警报
- 聚焦到 Textview
- 点击完成按钮退出 TextView
- 它不是在iOS5中辞职而是在iOS6中辞职
任何的想法?怎么了?