Search code examples
uitableviewuitextfieldtvos

Focus UITextField in TableViewCell on tvOS


in my AppleTV app, I have a custom UITableViewCell with UITextField inside.

What I'd like to achieve is to be able to focus this text field to enter text in it.

Unfortunately only the cell itself is focussing, I'm not able to focus the text field.

Thanks


Solution

  • The cell is getting focused because it returns YES from canBecomeFocused. If you want something within the cell to become focused, the cell needs to start returning NO from that method. There are two ways to do that: using the table view delegate method, or by subclassing UITableViewCell.

    In your table view's delegate, you can implement the method tableView:canFocusRowAtIndexPath: and return NO for the cells that contain text fields.

    Or, in your subclass of UITableViewCell, you could override canBecomeFocused to return NO.