Hi All,
- (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;
}
Hi Everyone, I am using this piece of code for getting the above output But when i am scrolling the tableview the output i am getting is
And if i enter any text in the section and scrolling the text, then the text is changing in the cells.
You need to use the
custom UITableViewCell
& in that class file, you need to get this tied up in the cell Class file . More importantly,need to maintain the datasource for it
.Don't use the
tag
as 0. I mean, set something similar for every viewstxtView.tag = 25+indexPath.section;