[英]Missing text in UITextField while calling becomeFirstResponder and setting text, if embedded in UINavigationController
I created a simple project as a test case for this issue. 我创建了一个简单的项目作为此问题的测试用例。
I have one simple view, with just one UITextField, embedded inside UINavigationController. 我有一个简单的视图,只有一个UITextField嵌入在UINavigationController中。
If I call: 如果我打电话给:
self.textField.text = @"TEST";
[self.textField becomeFirstResponder];
inside viewDidLoad. 在viewDidLoad内部。 Text field appears, but text is garbled, not visible or out of alignment.
出现文本字段,但文本乱码,不可见或不对齐。
If I either set text or call becomeFirstResponder in viewDidAppear this issue does not occur, but I don't get desired results as keyboard animation is delayed, and I need keyboard and text to be visible while new view shows up. 如果我在viewDidAppear中设置文本或调用成为firstFirstResponder,则不会发生此问题,但是由于键盘动画被延迟,因此无法获得期望的结果,并且在显示新视图时我需要键盘和文本可见。
Test Case: Test Project 测试案例: 测试项目
You can only call it on that view if it is part of a view hierarchy. 如果它是视图层次结构的一部分,则只能在该视图上调用它。 If the view's window property holds a UIWindow object.
如果视图的window属性包含一个UIWindow对象。 Try like this .
尝试这样。
-(void)viewWillAppear:(BOOL)animated
{
self.textField.text = @"TEST";
[super viewWillAppear:animated];
dispatch_async(dispatch_get_main_queue(), ^{
[self.textField becomeFirstResponder];
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.