TableView不再加载,而是以前



继续遇到此错误:2017-04-28 11:58:06.873 FIXEE [97466:2668136] ***断言失败 - [UaithitviewRowdata RectForrow:Insection:Insection:heepthCanbeguessed:]uikit-3600.6.21/uitaiteViewRowdata.m:1846

它正在工作,但是现在谈论行高度的问题,但是我确实返回了与我相同的值。谁能看到这个问题?我有两个tableviews,但一个称为hiretableview,另一个是.is tableview

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if(tableView == self.tableView){
        let cell  = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for : indexPath) as! CustomCell

        let bgColorView = UIView()

        //bgColorView.backgroundColor = UIColor.clear.withAlphaComponent(0.15)
        //bgColorView.backgroundColor = UIColor.red
        cell.selectedBackgroundView = bgColorView

        if indexPath.row % 2 == 0
        {
            if(indexPath.row == 0){
                cell.profileTitleLabel.text = problems[(indexPath as NSIndexPath).row].getTitle()
                if(problems[(indexPath as NSIndexPath).row].status == 0){
                    cell.profileStatusLabel.textColor = UIColor.red
                }
                else{
                    cell.profileStatusLabel.textColor = UIColor(red: 28/255.0, green: 121/255.0, blue: 125/255.0, alpha: 1.0)
                }
                cell.profileStatusLabel.text = "(problems[(indexPath as NSIndexPath).row].calculateSolved())"
                cell.profileMessageCountLabel.text = "(problems[(indexPath as NSIndexPath).row].commentCount)"
                cell.profileProblemImage.image =  problems[(indexPath as NSIndexPath).row].getImage()
                cell.profileUpdateLabel.text = "Last Update: 13:01   25/01/2017"
                cell.backgroundColor = UIColor.white

            }
            else{
                cell.profileTitleLabel.text = problems[(indexPath as NSIndexPath).row - indexPath.row / 2].getTitle()
                if(problems[(indexPath as NSIndexPath).row - indexPath.row / 2].status == 0){
                    cell.profileStatusLabel.textColor = UIColor.red
                }
                else{
                    cell.profileStatusLabel.textColor = UIColor(red: 28/255.0, green: 121/255.0, blue: 125/255.0, alpha: 1.0)
                }
                cell.profileStatusLabel.text = "(problems[(indexPath as NSIndexPath).row - indexPath.row / 2].calculateSolved())"
                cell.profileMessageCountLabel.text = "(problems[(indexPath as NSIndexPath).row - indexPath.row / 2].commentCount)"
                cell.profileProblemImage.image = problems[(indexPath as NSIndexPath).row - indexPath.row / 2].getImage()
                cell.profileUpdateLabel.text = "Last Update: 13:01   25/01/2017"
                cell.backgroundColor = UIColor.white

            }
        }
        else{
            cell.backgroundColor = UIColor.clear
            cell.profileTitleLabel.text = ""
            cell.profileStatusLabel.text = ""
            cell.profileMessageCountLabel.text = ""
            cell.profileProblemImage.image = nil
            cell.profileUpdateLabel.text = ""
            cell.selectionStyle = .none

        }
        return cell
    }
    else{
        let cell  = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for : indexPath) as! CustomCell
        cell.seperator.isHidden = true
        cell.bubble.isHidden = true
        let bgColorView = UIView()
        if indexPath.row % 2 == 0
        {
            if(indexPath.row == 0){
                cell.profileTitleLabel.text = ""
                cell.profileStatusLabel.text = ""
                cell.profileMessageCountLabel.text = ""
                cell.profileProblemImage.image = nil
                cell.profileUpdateLabel.text = ""
                cell.textLabel?.text = hires[(indexPath as NSIndexPath).row].title
                cell.detailTextLabel?.text = "(hires[(indexPath as NSIndexPath).row].price)"

            }
            else{
                cell.profileTitleLabel.text = ""
                cell.profileStatusLabel.text = ""
                cell.profileMessageCountLabel.text = ""
                cell.profileProblemImage.image = nil
                cell.profileUpdateLabel.text = ""
                cell.textLabel?.text = hires[(indexPath as NSIndexPath).row - indexPath.row / 2].title
                cell.detailTextLabel?.text = "(hires[(indexPath as NSIndexPath).row - indexPath.row / 2].price)"
            }
        }
        else{
            cell.backgroundColor = UIColor.clear
            cell.textLabel?.text = ""
            cell.detailTextLabel?.text = ""
            cell.selectionStyle = .none
            cell.profileTitleLabel.text = ""
            cell.profileStatusLabel.text = ""
            cell.profileMessageCountLabel.text = ""
            cell.profileProblemImage.image = nil
            cell.profileUpdateLabel.text = ""
        }

        return cell

    }


}


func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
    var height: CGFloat = 0
    if tableView == self.tableView {
        if indexPath.row % 2 == 0
        {
            height = 70 //cell height
        }
        else
        {
            height = 5 //space heigh
        }
    }
    if tableView == self.hireTableView {
        if indexPath.row % 2 == 0
        {
            height = 60 //cell height
        }
        else{
            height = 5 //space heigh
        }
    }

    return height
}

您需要对代码进行一些更改

  1. 用以下方式代替您的行:

    让Cell = self.tableview.dequeueereusablecell(withIdentifier:" cell"(为!CustomCell

  2. 对两个单元格都使用不同的标识符。

最新更新