Reputation: 6829
I have a UITableView
that I use as a form for registration I want when I click on first text input on the keyboard to have NEXT button. I have tried something but It always show DONE button and on it's tap it moves me to last text input.
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
if ([indexPath section] == 0) {
playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
if ([indexPath row] == 0) {
playerTextField.placeholder = @"Required";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.tag = 3;
}
else if([indexPath row] == 1){
playerTextField.placeholder = @"Required";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.tag = 4;
}
else if([indexPath row] == 2){
playerTextField.placeholder = @"[email protected]";
playerTextField.keyboardType = UIKeyboardTypeEmailAddress;
playerTextField.returnKeyType = UIReturnKeyNext;
playerTextField.tag = 1;
}
else {
playerTextField.placeholder = @"password";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.secureTextEntry = YES;
playerTextField.tag = 2;
}
playerTextField.backgroundColor = [UIColor whiteColor];
playerTextField.autocorrectionType = UITextAutocorrectionTypeNo;
playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
playerTextField.textAlignment = NSTextAlignmentLeft;
playerTextField.delegate = self;
playerTextField.clearButtonMode = UITextFieldViewModeNever;
[playerTextField setEnabled: YES];
playerTextField.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addSubview:playerTextField];
}
}
if ([indexPath section] == 0) { // Email & Password Section
if ([indexPath row] == 0) { // Email
cell.textLabel.text = @"First Name";
}
else if ([indexPath row] == 1) { // Email
cell.textLabel.text = @"Last Name";
}
else if([indexPath row] == 2){
cell.textLabel.text = @"Email";
}
else {
cell.textLabel.text = @"Password";
}
}
return cell;
}
...
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
if(textField.tag == 3) {
[playerTextField becomeFirstResponder];
}else if(textField.tag == 4) {
[playerTextField becomeFirstResponder];
}else if(textField.tag == 1) {
[playerTextField becomeFirstResponder];
} else if(textField.tag == 2) {
[playerTextField resignFirstResponder];
}
return NO;
}
Upvotes: 0
Views: 123
Reputation: 8402
change this
playerTextField.returnKeyType = UIReturnKeyDone;
to
playerTextField.returnKeyType = UIReturnKeyNext;
rest of the code in the link->"in comment" to move to next text field
Upvotes: 3