When i scroll the tableview up and down the content in the cells gets overlapped, Why is this and how can i correct it ?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
IndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
}
UITextField* tf = nil ;
switch ( indexPath.row ) {
case 0: {
cell.textLabel.text = @"First Name" ;
tf = firstNameTextField = [self makeTextField:self. placeholder:@"F name"];
[cell.contentView addSubview:firstNameTextField];
break ;
}
case 1: {
cell.textLabel.text = @"Last Name" ;
tf = lastNameTextField = [self makeTextField:self.lastName placeholder:@"L name"];
[cell.contentView addSubview:lastNameTextField];
break ;
}
case 2: {
cell.textLabel.text = @"age" ;
tf = agetextfield = [self makeTextField:self.password placeholder:@"Age"];
[cell.contentView addSubview:agetextfield];
break ;
}
}
return cell;
The cells were reused in this case. So the cells are overlapped on others. Just modify your code to resolve this.