gpt4 book ai didi

ios - TableView 不再加载但之前

转载 作者:行者123 更新时间:2023-11-28 08:11:18 26 4
gpt4 key购买 nike

继续遇到这个错误:2017-04-28 11:58:06.873 Fixee[97466:2668136] *** 断言失败 -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/UITableViewRowData.m:1846

它工作正常,但现在谈论行高时崩溃了,但我确实返回了与我所拥有的相同的值。任何人都可以看到这个问题吗?我有两个 tableview,但一个叫 hireTableView,另一个是 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.dequeueReusableCell(withIdentifier: "Cell") 作为!自定义单元格

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

关于ios - TableView 不再加载但之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43678637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com