简体   繁体   中英

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:

- (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).

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.

Can anyone tell me if this particular code serves any purpose on the 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. As you mentioned, first responder status is typically handled by UI controls.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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