Tableview单元格覆盖

什卡·夏尔马

下面是我的代码,当我滚动并在if(cell == nil)下放置内容时,单元格被覆盖,什么也没有显示,我不知道如何摆脱它。当我一次又一次滚动时,它只是覆盖。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView       dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    UILabel *boothtitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 3, self.view.frame.size.width*0.5-3, 25)];
    UILabel *HouseTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 31, self.view.frame.size.width*0.5-3, 25)];
    UILabel *NameTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 59, self.view.frame.size.width*0.5-3, 25)];
    UILabel *FHNTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 87, self.view.frame.size.width*0.5-3, 25)];
    UILabel *EPICTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 115, self.view.frame.size.width*0.5-3, 25)];

    UILabel *BoothNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 3, 200, 25)];
    UILabel *HouseNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 31, 200, 25)];
    UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 59, 200, 25)];
    UILabel *EPIC=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 87, 200, 25)];
    UILabel *Fnaaam=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 115, 200, 25)];

    [cell.contentView addSubview:boothtitle];
    [cell.contentView addSubview:HouseTitle];
    [cell.contentView addSubview:NameTitle];
    [cell.contentView addSubview:FHNTitle];
    [cell.contentView addSubview:EPICTitle];

    [cell.contentView addSubview:BoothNo];
    [cell.contentView addSubview:Name];
    [cell.contentView addSubview:HouseNo];
    [cell.contentView addSubview:EPIC];
    [cell.contentView addSubview:Fnaaam];
    boothtitle.text=@"Booth Number";
    HouseTitle.text=@"House Number";
    NameTitle.text=@"Name";
    FHNTitle.text=@"F/H/M Name";
    EPICTitle.text=@"EPIC";

    BoothNo.text=[BotthID objectAtIndex:indexPath.row];
    Name.text=[nname objectAtIndex:indexPath.row];
    HouseNo.text=[Houseno objectAtIndex:indexPath.row];
    EPIC.text=[EpiC objectAtIndex:indexPath.row];
    Fnaaam.text=[FName objectAtIndex:indexPath.row];

    return cell;

}
什卡·夏尔马

我解决了,我只是改变了条件。下面是代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView       dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell != nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    UILabel *boothtitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 3, self.view.frame.size.width*0.5-3, 25)];
    UILabel *HouseTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 31, self.view.frame.size.width*0.5-3, 25)];
    UILabel *NameTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 59, self.view.frame.size.width*0.5-3, 25)];
    UILabel *FHNTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 87, self.view.frame.size.width*0.5-3, 25)];
    UILabel *EPICTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 115, self.view.frame.size.width*0.5-3, 25)];
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.5+90, 7, 25, 25)];

    icon.image=[UIImage imageNamed:@"edit.png"];

    UILabel *BoothNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 3, 200, 25)];
    UILabel *HouseNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 31, 200, 25)];
    UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 59, 200, 25)];
    UILabel *EPIC=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 87, 200, 25)];
    UILabel *Fnaaam=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 115, 200, 25)];

    [cell.contentView addSubview:boothtitle];
    [cell.contentView addSubview:HouseTitle];
    [cell.contentView addSubview:NameTitle];
    [cell.contentView addSubview:FHNTitle];
    [cell.contentView addSubview:EPICTitle];

    [cell.contentView addSubview:icon];

    [cell.contentView addSubview:BoothNo];
    [cell.contentView addSubview:Name];
    [cell.contentView addSubview:HouseNo];
    [cell.contentView addSubview:EPIC];
    [cell.contentView addSubview:Fnaaam]; 
    boothtitle.text=@"Booth Number";
    HouseTitle.text=@"House Number";
    NameTitle.text=@"Name";
    FHNTitle.text=@"F/H/M Name";
    EPICTitle.text=@"EPIC";

    BoothNo.text=[BotthID objectAtIndex:indexPath.row];
    Name.text=[nname objectAtIndex:indexPath.row];
    HouseNo.text=[Houseno objectAtIndex:indexPath.row];
    EPIC.text=[EpiC objectAtIndex:indexPath.row];
    Fnaaam.text=[FName objectAtIndex:indexPath.row];

    return cell;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

带有内容的Tableview单元格用白色覆盖?

来自分类Dev

动态Tableview单元格

来自分类Dev

创建tableView单元格

来自分类Dev

Tableview单元格偏移

来自分类Dev

TableView 单元格操作

来自分类Dev

从任何单元格点拖动tableView单元格

来自分类Dev

deleteRowsAtIndexPaths动画覆盖上单元格

来自分类Dev

数据覆盖UITableView单元格

来自分类Dev

python写入excel覆盖单元格

来自分类Dev

表格视图单元格覆盖数据

来自分类Dev

如何覆盖显示:表格单元格

来自分类Dev

在tableView中搜索单元格问题

来自分类Dev

在TableView中编辑数字单元格

来自分类Dev

TableView,设置可编辑单元格

来自分类Dev

tableview静态单元格动态页脚

来自分类Dev

快速隐藏Tableview的静态单元格

来自分类Dev

TableView单元格内部的UIActivityIndicatorView

来自分类Dev

如何摆脱特定的TableView单元格

来自分类Dev

TableView单元格自动换行

来自分类Dev

TableView单元格在滚动时消失

来自分类Dev

TableView单元格错误-iOS / Swift

来自分类Dev

TableView-编辑焦点单元格

来自分类Dev

快速查看Tableview单元格

来自分类Dev

单击按钮展开tableview单元格

来自分类Dev

动态更改TableView单元格的高度

来自分类Dev

展开和折叠tableview单元格

来自分类Dev

单元格隐藏属性[tableView]

来自分类Dev

tableView添加额外的(空)单元格

来自分类Dev

Tableview显示错误的单元格大小