Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically Select First UITableView Textbox

I have a tableview that accepts login credentials. I would like to have my app automatically select the first tableview text box upon loading or appearing. I would like the cursor to be placed in the "Email Address" field and for the keyboard to be raised automatically. I can't seem to figure this out. Anyone have any ideas? Thank you!

enter image description here

like image 845
Brandon Avatar asked Feb 18 '23 10:02

Brandon


2 Answers

You have to assign the first responder to that UITextView...

For example:

[textField becomeFirstResponder]

You can do it in the viewDidAppear of the UIViewController.

like image 80
apascual Avatar answered Feb 19 '23 23:02

apascual


- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

myTextField = (UITextField *)[cell viewWithTag:kMyTextFieldTag];
[myTextField becomeFirstResponder];
}
like image 39
Baby Groot Avatar answered Feb 20 '23 01:02

Baby Groot