继续遇到此错误: 2017-04-28 11:58:06.873 Fixee [97466:2668136] ***断言失败 - [UITableViewRowData rectForRow:inSection:heightCanBeGuessed:],/ BuildRoot / Library / Cache / com.apple.xbs / Source / 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
}
答案 0 :(得分:0)
您需要对代码进行一些更改
用这个替换你的行:
让cell = self.tableView.dequeueReusableCell(withIdentifier:" Cell")为! CustomCell
为两个单元格使用不同的标识符。