のサブビューUITextView
として追加しました。ユーザーがキーボードを辞退できるように、[完了] ボタンを ( を使用して)UIAlertView
追加しました。iOS6.0で問題なく動いています。iOS5.0ではありません。UIToolBar
UIBarButtonItem
inputAccessoryView
一応ブレイクポイントを入れて確認したところ、自分なりに再確認のため、サンプルプロジェクトを作って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 を辞任します。
- iOS5 での辞任ではなく、iOS6 での辞任
何か案が?何がうまくいかないのですか?