Xcode
创建基于视图的iPhone项目(我使用xcode 4,但我猜xcode 3的行为相同)将以下代码放入applicationDidFinishLaunchingMethod
:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
self.viewController.view.backgroundColor = [UIColor redColor];
UIViewController *modalVc = [UIViewController new];
modalVc.view.backgroundColor = [UIColor greenColor];
[self.viewController presentModalViewController:modalVc animated:NO];
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 20, 150, 30)];
tf.borderStyle = UITextBorderStyleRoundedRect;
[self.window addSubview:tf];
[tf becomeFirstResponder];
[self.viewController performSelector:@selector(dismissModalViewControllerAnimated:) withObject:NO afterDelay:3];
return YES;
}
运行应用程序时,您会注意到,当modalViewController被解除时,键盘会消失,文本区域会聚焦(光标仍然闪烁)
实际上我的项目正在使用另一个窗口来显示文本视图层次结构,但它看起来甚至在同一个窗口中也会发生。我还尝试将文本字段放入属于视图控制器的视图中,并将该视图添加到具有相同结果的窗口。
Apple接受此方法([UIWindow addSubView:])将视图控制器的视图添加到屏幕上,所以它看起来像个错误
问题: