iPad UITextField将不会返回

时间:2010-08-10 06:44:42

标签: ipad uitextfield

我在UITableViewCell中有一个UITextField。 我希望textField返回但出现问题。 这是我的代码:


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            usernameField = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height)];
            usernameField.adjustsFontSizeToFitWidth = YES;
            usernameField.placeholder = @"Username";
            usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
            usernameField.backgroundColor = [UIColor clearColor];
            usernameField.keyboardType = UIKeyboardTypeDefault;
            usernameField.autocapitalizationType = UITextAutocapitalizationTypeNone;
            usernameField.autocorrectionType = UITextAutocorrectionTypeNo;
            usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            usernameField.returnKeyType = UIReturnKeyDone;
            usernameField.delegate = self;
            usernameField.clearButtonMode = UITextFieldViewModeAlways;
            [usernameField setEnabled:YES];
            [cell addSubview:usernameField];
            [usernameField becomeFirstResponder];
            [usernameField release];            
        }
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

我还将我的课程实现到了UITextFieldDelegate

谢谢!

1 个答案:

答案 0 :(得分:0)

我只是遇到了类似的问题。对UITableViewCell进行子类化是一种更清晰的方法。 以下链接将为您提供良好的开端。