Я создал экран входа в систему, используя UITableView с одним разделом и двумя ячейками.Вот как эти клетки создаются.Теперь я не знаю, как получить значения из этих ячеек позже.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"LoginCellIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 25)];
leftLabel.backgroundColor = [UIColor clearColor];
leftLabel.tag = 1;
[cell.contentView addSubview:leftLabel];
[leftLabel release];
UITextField *valueTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 10, 400, 35)];
valueTextField.tag = 2;
valueTextField.delegate = self;
[cell.contentView addSubview:valueTextField];
[valueTextField release];
}
if (indexPath.row == 0) { // User name
UILabel *lblText = (UILabel *)[cell.contentView viewWithTag:1];
lblText.text = @"Username: ";
UITextField *userNameField = (UITextField *)[cell.contentView viewWithTag:2];
userNameField.placeholder = @"Enter your username here";
}
else { // Pass word
UILabel *lblText = (UILabel *)[cell.contentView viewWithTag:1];
lblText.text = @"Password: ";
UITextField *passwordField = (UITextField *)[cell.contentView viewWithTag:2];
passwordField.placeholder = @"Enter your password here";
passwordField.secureTextEntry = YES;
}
return cell;
}
Точно, я хочу получить значение, когда пользователь нажимает клавишу return .Итак, я хочу получить значения текстового поля ячейки здесь ...
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"%@ is the Value", textField.text);
[textField resignFirstResponder];
return YES;
}
Но я не знаю, как получить значения этих текстовых полей.Интересно, будет cellForRowAtIndexPath для пути индекса работать в этом случае или нет?