问题 1 :
cell中放置标签后,上下滑动tableView,标签上的文本重叠。
解决办法:
把标签remove掉
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
staticNSString*CellIdentifier =@"Cell";
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell ==nil) {
cell= [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
for (UIView *a in cell.contentView.subviews)
{
if([a isKindOfClass:[UILabel class]])
{
[a removeFromSuperview];
}
}
...
}
问题 2 :
多个section 结构不一样时,tableview显示混乱
解决办法:
对每个section,分别重用cell
if (indexPath.section ==0)
{
static NSString *CellIdentifier =@"Cell0";
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if(cell ==nil) {
cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]autorelease];
}
…
return cell;
}
elseif(indexPath.section == 1)
{
static NSString*CellIdentifier =@"Cell1";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if(cell ==nil) {
cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]autorelease];
}
…
return cell;
}
问题 3:
有三个结果一样的section ,每行row分别定义
if (indexPath.row ==0)
{
...cell.textLabel.text =string1;
}
elseif(indexPath.row == 1)
{
...cell.textLabel.text =sring2;
}
else if(indexPath.row == 2)
{
cell.textLabel.text =@"";
UILabel *label2 = [[UILabelalloc]initWithFrame:CGRectMake(10,20,100,40)];
label2.text =@"餐桌人员:";
label2.tag =98;
//label1.font = [UIFont systemFontOfSize:18];
UILabel *label22 = [[UILabelalloc]initWithFrame:CGRectMake(110,10,180,60)];
label22.text = [[[[dicobjectForKey:@"result"]objectForKey:@"deskList"]objectAtIndex:indexPath.section]objectForKey:@"members"];
label22.tag =99;
label22.numberOfLines =0;
label2.backgroundColor = [UIColorclearColor];
label22.backgroundColor = [UIColorclearColor];
[cell.contentViewaddSubview:label2];
[cell.contentViewaddSubview:label22];
}
运行后,发现上下滑动tableview后,数据串变,不在指定的row显示指定的内容
解决办法:
if(indexPath.row ==2)
中加上 cell.textLabel.text =@"";
indexPath.row ==2时,重用的cell还留有上一次的cell.textLabel.text内容,没有对其更新的话可能会覆盖掉加上去的label