Last active
          October 3, 2018 23:19 
        
      - 
      
 - 
        
Save ordovician/92dd8941d41d9c350c7c to your computer and use it in GitHub Desktop.  
    [Tap anywhere in text cell] How to make UITextField first responder when tapping anywhere inside a table view cell. Just like Apple's "Settings" app. #firstresponder #viewcell
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Settings : UITableViewController { | |
| override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
| let cell = tableView.cellForRowAtIndexPath(indexPath) | |
| // The cells contentview is the one containing custom added components. | |
| if let subviews = cell?.contentView.subviews { | |
| // Find a subview which is a UITextField. Place cursor in this textfield. | |
| for view in subviews { | |
| if let textfield = view as? UITextField { | |
| textfield.becomeFirstResponder() | |
| break | |
| } | |
| } | |
| } | |
| } | |
| } | 
      
          
      
      
            galahador
  
      
      
      commented 
        May 29, 2018 
      
    
  
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment