滚动后UITableView设计无法正常工作

时间:2016-02-24 14:34:04

标签: ios objective-c uitableview custom-cell

我在我的应用程序中使用了UITableView并使用了自定义Cell,当查看午餐它工作得很好但滚动表再次设置它就像丑陋,像图像一样。 My normal tableView My tableView after Scrolling

DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.sellPropertyLabel.text=sellPropertyArray[indexPath.row];
cell.sellPropertyTextField.delegate=self;

if (indexPath.row==0)
{

    cell.sellPropertyTextField.tag=indexPath.row;
    if (_realEstateTitle)
    {
        cell.sellPropertyTextField.text=_realEstateTitle;
    }

}
else if (indexPath.row==1)
{

    cell.sellPropertyTextField.tag=indexPath.row;
    if (_desOfHomeInterior)
    {
        cell.sellPropertyTextField.text=_desOfHomeInterior;
    }

}
else if (indexPath.row==2)
{
    cell.sellPropertyTextField.tag=indexPath.row;
    if (_desOfGardenAndExter)
    {
        cell.sellPropertyTextField.text=_desOfGardenAndExter;
    }

}
else if (indexPath.row==3)
{
    cell.sellPropertyTextField.tag=indexPath.row;
    if (_locationOfTheProperty)
    {
        cell.sellPropertyTextField.text=_locationOfTheProperty;
    }



}
else if (indexPath.row==4)
{

    cell.sellPropertyTextField.tag=indexPath.row;
    if (_whyBuyThisProperty)
    {
        cell.sellPropertyTextField.text=_whyBuyThisProperty;
    }



}
else if (indexPath.row==5)
{
    //cell.selected=YES;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    cell.sellPropertyTextField.enabled=NO;
    if (_country)
    {
        cell.sellPropertyTextField.text=_country;
    }



}
else if (indexPath.row==6)
{
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    cell.sellPropertyTextField.enabled=NO;
    if (_city)
    {
        cell.sellPropertyTextField.text=_city;
    }


}
else if (indexPath.row==7)
{
    cell.sellPropertyTextField.enabled=NO;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    if (_area)
    {
        cell.sellPropertyTextField.text=_area;
    }


}
else if (indexPath.row==8)
{

    cell.sellPropertyTextField.enabled=NO;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    if (_type)
    {
        cell.sellPropertyTextField.text=_type;
    }

    //cell.addAlertTextField.keyboardType=UIKeyboardTypePhonePad;

}


else if (indexPath.row==9)
{
    cell.sellPropertyTextField.enabled=NO;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    if (_pool)
    {
        cell.sellPropertyTextField.text=_pool;
    }



}
else if (indexPath.row==10)
{
    cell.sellPropertyTextField.enabled=NO;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    if (_status)
    {
        cell.sellPropertyTextField.text=_status;
    }



}
else if (indexPath.row==11)
{


    cell.sellPropertyTextField.tag=indexPath.row;
    if (_bedrooms)
    {
        cell.sellPropertyTextField.text=_bedrooms;
    }



}
else if (indexPath.row==12)
{


    cell.sellPropertyTextField.tag=indexPath.row;
    if (_bathrooms)
    {
        cell.sellPropertyTextField.text=_bathrooms;
    }



}
else if (indexPath.row==13)
{


    cell.sellPropertyTextField.tag=indexPath.row;
    if (_livingSpaceSqm)
    {
        cell.sellPropertyTextField.text=_livingSpaceSqm;
    }


}
else if (indexPath.row==14)
{


    cell.sellPropertyTextField.tag=indexPath.row;
    if (_landSqm)
    {
        cell.sellPropertyTextField.text=_landSqm;
    }


}
else if (indexPath.row==15)
{


    cell.sellPropertyTextField.tag=indexPath.row;
    if (_price)
    {
        cell.sellPropertyTextField.text=_price;
    }



}
else if (indexPath.row==16)
{
    //cell.addAlertTextField.enabled=NO;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.sellPropertyTextField.tag=indexPath.row;
    cell.sellPropertyTextField.enabled=NO;
    if (_currency)
    {
        cell.sellPropertyTextField.text=_currency;
    }


}

return cell;

}

2 个答案:

答案 0 :(得分:0)

问题是您对单元格使用相同的reuseIdentifier。请分享您的cellForRowAtIndexPath方法,但我相信您有"ID"之类的字符串。您有两种具有不同配置的单元格,因此您也应该使用不同的标识符。例如,"ID1"表示第一类单元格,"ID2"表示其他单元格。

This simple example should fix the problem

NSString *identifier = nil;
NSInteger row = indexPath.row;
if ((row >= 5 && row <= 10) || row == 16) {
    identifier = @"CELLID1";
}
else {
    identifier = @"CELLID2";
}


DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
....

或更简单的解决方案就是在您的案例的方法开头清除accessoryType

DetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;

答案 1 :(得分:0)

您需要检查单元格,因为它们正在重复使用。

您的代码结构有点难以修改,有时切换案例会更好。你可以在返回单元格之前在底部添加它:

==