简体   繁体   English

UITableViewController上的第一响应者?

[英]First responder on UITableViewController?

I've been given some old code to update (from the iOS 5 era), and there's a chunk of code in it that I don't quite understand: 我得到了一些旧的代码来更新(从iOS 5时代开始),其中有很多我不太了解的代码:

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

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

This is part of a UITableViewController subclass which instantiates a bunch of custom UITableViewCell subclasses that all contain UITextFields (the input of which is validated and processed by the UITableViewCell subclass, before being passed back to the UITableViewController via a delegate method). 这是UITableViewController子类的一部分,该子类实例化了一堆自定义UITableViewCell子类,这些子类都包含UITextField(其输入由UITableViewCell子类验证和处理,然后再通过委托方法传递回UITableViewController)。

AFAIK, UIResponder stuff such as becomeFirstResponder and canBecomeFirstResponder has more to do with user interactive control widgets (like text fields and stuff), rather than table view controllers. AFAIK,UIResponder之类的东西(例如beginFirstResponder和canBecomeFirstResponder)与用户交互式控件(例如文本字段和内容)有更多关系,而不是与表视图控制器有关。

Can anyone tell me if this particular code serves any purpose on the UITableViewController? 谁能告诉我这个特定的代码是否在UITableViewController上有任何作用? Or is it something I can delete? 还是我可以删除的东西? The behaviour of the application doesn't seem to change whether it's there or not. 应用程序的行为似乎没有改变,无论它是否存在。

If this is indeed a subclass of UITableViewController, you shouldn't need the mentioned code at all. 如果确实是UITableViewController的子类,则完全不需要所提到的代码。 As you mentioned, first responder status is typically handled by UI controls. 如您所述,第一响应者状态通常由UI控件处理。

That being said, be on the lookout in case the developers tried to do some really funky (unclean) stuff like force-setting the UITableViewController as firstResponder then having another piece of code forward a request to the firstResponser expecting it to be the UITableViewController, or attaching some methods in a NIB to the firstResponder object. 话虽这么说,当开发人员尝试做一些非常时髦(不干净)的事情时,请小心,比如将UITableViewController强制设置为firstResponder,然后让另一段代码将请求转发给firstResponser,期望它是UITableViewController,或者将NIB中的某些方法附加到firstResponder对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM