大家好,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 5, 200, 30)];
textField.tag = 123;
textField.placeholder = @"Enter Text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.delegate = self;
[cell.contentView addSubview:textField];
}
UITextField *textField = (UITextField *) [cell.contentView viewWithTag:123];
if (indexPath.row == 0) {
[textField setPlaceholder:@"Employee ID"];
}
else if (indexPath.row == 1)
{
[textField setPlaceholder:@"Employee Name"];
}
else if (indexPath.row == 2)
{
[textField setPlaceholder:@"Employee Phone"];
}
if (indexPath.row == 3)
{
[textField setPlaceholder:@"Employee Email"];
UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[saveButton setFrame:CGRectMake(200, 0, 100, 40)];
[saveButton setTitle:@"Save Emp" forState:UIControlStateNormal];
[saveButton addTarget:self action:@selector(saveEmployeeToCoreData:) forControlEvents:UIControlEventTouchUpInside];
[saveButton setTag:indexPath.section];
[cell addSubview:saveButton];
}
return cell;
}
大家好,我正在使用这段代码来获取上述输出但是当我滚动表格视图时,我得到的输出是
如果我在该部分中输入任何文本并滚动文本,那么单元格中的文本会发生变化。