我正在开发基于消息的 iPhone 应用程序。我有一个屏幕来回复收到的消息。此屏幕包含两个 UITextView,例如 bottomTextView 和 topTextView。
topTextView 被添加为 bottomTextView 的 InputAccessory 视图。
当用户进入屏幕时topTextView
必须成为FirstResponder。它正在显示,但光标未放在 topTextView 中。光标位于 textview 中bottomTextView
。如何使 topTextView 成为有光标的第一响应者?
这是我尝试过的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
bottomBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 320, 40)];
bottomBarViewImage.image = [UIImage imageNamed: @"toolbarbg~iphone.png"];
[bottomBarView addSubview: bottomBarViewImage];
[self.view addSubview: bottomBarView];
bottomTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 7.5, 210, 25)];
bottomTextView.delegate = self;
bottomTextView.backgroundColor = [UIColor clearColor];
bottomTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
bottomTextView.scrollEnabled = NO;
[bottomBarView addSubview: bottomTextView];
topBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 320, 40)];
topBarViewImage.image = [UIImage imageNamed: @"toolbarbg~iphone.png"];
[topBarView addSubview: topBarViewImage];
topTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 7.5, 210, 25)];
topTextView.delegate = self;
topTextView.backgroundColor = [UIColor clearColor];
topTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
topTextView.scrollEnabled = NO;
[topBarView addSubview: topTextView];
[bottomTextView becomeFirstResponder];
[bottomTextView setInputAccessoryView: topBarView];
}
-(void) textViewDidBeginEditing:(UITextView *)textView
{
if(textView == bottomTextView)
{
bottomTextView.scrollEnabled = NO;
[topTextView becomeFirstResponder];
}
}
topTextView
with正在显示,topBarView
但光标未放在 topTextView 中。你能帮我解决这个问题吗?提前致谢。