當我上下滾動tableview時,單元格中的內容會重疊,爲什麼是這樣以及如何糾正它?當TableView滾動時,單元格內容重疊
- (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;
沒有變化,我仍然得到相同的結果。 – Illep 2012-03-23 16:33:01
您是否嘗試過cell.contentView = lastNameTextField – rakeshNS 2012-03-23 16:38:36
並將樣式更改爲UITableViewCellStyleDefault – rakeshNS 2012-03-23 16:39:59