下一个按钮不显示

时间:2013-09-05 10:01:28

标签: iphone ios objective-c uitableview uitextfield

我有一个UITableView我用作注册表单,当我点击键盘上的第一个文本输入以获得 NEXT 按钮时。我尝试了一些东西,但它总是显示 DONE 按钮,然后点击它会将我移动到最后一个文本输入

- (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 = @"example@gmail.com";
                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;
}

1 个答案:

答案 0 :(得分:3)

更改此

     playerTextField.returnKeyType = UIReturnKeyDone;

     playerTextField.returnKeyType = UIReturnKeyNext; 

链接中的其余代码 - >“在评论中”移动到下一个文本字段