gpt4 book ai didi

ios - 为什么 becomeFirstResponder 不起作用?

转载 作者:IT王子 更新时间:2023-10-29 08:04:00 28 4
gpt4 key购买 nike

我使用 AGWindowView 添加了一个模态框.在模态视图(使用 IB 构建)中,有一个文本字段。文本字段已连接到 socket 。

这行不通:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.placesTextField becomeFirstResponder];
}

becomeFirstResponder 的调用不起作用,键盘也没有显示。

这个有效:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.placesTextField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];
}

但是,如果我使用 performSelector:withObject:afterDelay 手动发送消息,它会起作用。为什么直到运行时才确定此方法?

最佳答案

似乎在 iOS7 中, View /对象还没有附加到 View 层次结构/窗口中。因此通过对象调用方法失败。如果我们进行一些延迟并且它正在工作,则意味着此时对象已附加到窗口。

根据苹果公司的说法,

A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.

You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.

有关详细信息,请参阅 UIResponder Class Reference .

关于ios - 为什么 becomeFirstResponder 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20208837/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com