これが私のコードです。セクション 0 にはタイトルが表示されますが、テキストフィールドやプレースホルダーは表示されません。セクション1は大丈夫です!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
// Make cell unselectable and set font.
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:12];
if (indexPath.section == 0) {
UITextField* tf = nil;
switch ( indexPath.row ) {
case 0: {
cell.textLabel.text = @"Name" ;
tf = nameFieldTextField = [self makeTextField:self.name placeholder:@"John Appleseed"];
[cell addSubview:nameFieldTextField];
break ;
}
case 1: {
cell.textLabel.text = @"Address" ;
tf = addressFieldTextField = [self makeTextField:self.address placeholder:@"Street Address"];
[cell addSubview:addressFieldTextField];
break ;
}
case 2: {
cell.textLabel.text = @"Email" ;
tf = emailFieldTextField = [self makeTextField:self.email placeholder:@"example@gmail.com"];
[cell addSubview:emailFieldTextField];
break ;
}
case 3: {
cell.textLabel.text = @"Phone" ;
tf = phoneFieldTextField = [self makeTextField:self.phone placeholder:@"XXX-XXX-XXXX"];
[cell addSubview:phoneFieldTextField];
break ;
}
}
} else if (indexPath.section == 1) {
UITextField* tf = nil;
switch ( indexPath.row ) {
case 0: {
cell.textLabel.text = @"Company" ;
tf = workNameTextField = [self makeTextField:self.workName placeholder:@"Company Name"];
[cell addSubview:workNameTextField];
break ;
}
case 1: {
cell.textLabel.text = @"Address" ;
tf = workAddressTextField = [self makeTextField:self.workAddress placeholder:@"Work Address"];
[cell addSubview:workAddressTextField];
break ;
}
case 2: {
cell.textLabel.text = @"Phone" ;
tf = workPhoneTextField = [self makeTextField:self.workPhone placeholder:@"xxx-xxx-xxxx"];
[cell addSubview:workPhoneTextField];
break ;
}
case 3: {
cell.textLabel.text = @"Title" ;
tf = workTitleTextField = [self makeTextField:self.workTitle placeholder:@"Position"];
[cell addSubview:workTitleTextField];
break ;
}
case 4: {
cell.textLabel.text = @"Manager" ;
tf = workManagerTextField = [self makeTextField:self.workManager placeholder:@"Mr. Boss"];
[cell addSubview:workManagerTextField];
break ;
}
case 5: {
cell.textLabel.text = @"Manager Phone" ;
tf = workManagerPhoneTextField = [self makeTextField:self.workManagerphone placeholder:@"XXX-XXX-XXXX"];
[cell addSubview:workManagerPhoneTextField];
break ;
}
case 6: {
cell.textLabel.text = @"Annual Salary" ;
tf = workManagerPhoneTextField = [self makeTextField:self.workManagerphone placeholder:@"$50,000"];
[cell addSubview:workManagerPhoneTextField];
break ;
}
}
// Textfield dimensions
tf.frame = CGRectMake(120, 12, 170, 30);
// Workaround to dismiss keyboard when Done/Return is tapped
[tf addTarget:self action:@selector(textFieldFinished:) forControlEvents:UIControlEventEditingDidEndOnExit];
}
return cell;
}