我的 iPhone 应用程序中有两个UITextView
。当用户选择一个UITextView
控制器自动转到另一个UITextView
。我在我的项目中尝试了以下方式。但是第二个UITextView
直到becomefirstresponder
用户在第二个里面点击才会出现UITextView
。
-(void) viewDidLoad
{
TextView1 = [[UITextView alloc] initWithFrame:CGRectMake(10, 320, 300, 50)];
TextView1.delegate = self;
TextView1.backgroundColor = [UIColor clearColor];
TextView1.layer.borderWidth = 2;
TextView1.layer.borderColor = [UIColor blackColor].CGColor;
TextView1.layer.cornerRadius = 5;
[self.view addSubview: TextView1];
TextView2 = [[UITextView alloc] initWithFrame:CGRectMake(10, 5, 300, 30)];
TextView2.delegate = self;
TextView2.backgroundColor = [UIColor whiteColor];
TextView2.layer.borderWidth = 2;
TextView2.layer.borderColor = [UIColor lightTextColor].CGColor;
TextView2.layer.cornerRadius = 5;
[self.view addSubview: TextView2];
UIBarButtonItem *textBarButton = [[UIBarButtonItem alloc] initWithCustomView: TextView2];
accessoryToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
accessoryToolBar.items = [NSArray arrayWithObjects:textBarButton, nil];
}
-(BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"TextView Should Begin Editing");
if (textView == messageTextView)
{
[TextView2 setInputAccessoryView:accessoryToolBar];
[TextView1 resignFirstResponder];
[TextView2 becomeFirstResponder];
}
else
{
[TextView2 setInputAccessoryView:accessoryToolBar];
[TextView1 resignFirstResponder];
}
return YES;
}
我怎样才能解决这个问题?