所以,我正在使用 UITableView 创建一个登录屏幕。电子邮件和密码有两个文本字段。当用户按下“登录”按钮时,我想将这两个文本字段的内容存储在两个 NSString 中。我怎么做?这是 cellForRowAtIndexPath 的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"Cell";
UITextField *tf = [[UITextField alloc] init];
UITableViewCell *cell = [self.tView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
if ([indexPath section] == 0) {
UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 250, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
if ([indexPath row] == 0) {
playerTextField.placeholder = @"Email";
playerTextField.keyboardType = UIKeyboardTypeEmailAddress;
playerTextField.returnKeyType = UIReturnKeyNext;
tf = jidField = [self makeTextField:@"" placeholder:playerTextField.placeholder];
[cell addSubview:jidField];
}
else {
playerTextField.placeholder = @"Password";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.secureTextEntry = YES;
}
//playerTextField.backgroundColor = [UIColor whiteColor];
playerTextField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
playerTextField.textAlignment = NSTextAlignmentLeft;
// playerTextField.tag = 0;
//playerTextField.delegate = self;
playerTextField.clearButtonMode = YES; // no clear 'x' button to the right
[playerTextField setEnabled: YES];
[cell addSubview:playerTextField];
}
}
return cell;
}