1 つのセクションと 2 つのセルを持つ 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 が機能するのだろうか?