【问题标题】:SWRevealViewController Cells show up blank until clickSWRevealViewController 单元格显示为空白,直到单击
【发布时间】:2018-01-19 09:39:49
【问题描述】:

我正在使用 SWRevealViewController,当我创建单元格并运行应用程序时,侧面菜单显示为空白。但是,一旦单击其中一个单元格,就会出现该单元格。但是,当您单击它时,顶部较大的单元格仍然不会出现。这是我的代码。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return menuTitle.count+3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let index = indexPath.row
    var defCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
    switch (index) {
        case 0:
            let cell = tableView.dequeueReusableCell(withIdentifier: "profileCell") as! profileCell
            cell.nameLbl.text = "Name Here"   //need to pull name from the database here
            cell.profileImg.image = UIImage(named: "face")! //pull from db
            print(cell)
            return cell
        case 1:
            let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell") as! labelCell
            cell.menuLabel.text = "For Sale"
            return cell
        case 2,3,4:
            let cell = tableView.dequeueReusableCell(withIdentifier: "titleCells") as! titleCells
            cell.cellImg.image = iconImg[indexPath.row - 2]
            cell.cellName.text! = menuTitle[indexPath.row - 2]
            return cell
        case 5:
            let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell") as! labelCell
            cell.menuLabel.text = "Profile"
            //labelCell.darkLine //cahnge line color to orange
            return cell
        case 6,7,8,9,10,11:
            print(indexPath.row)
            let cell = tableView.dequeueReusableCell(withIdentifier: "titleCells") as! titleCells
            cell.cellImg.image = iconImg[indexPath.row - 3]
            cell.cellName.text! = menuTitle[indexPath.row - 3]
            print(menuTitle[indexPath.row - 3])
            return cell
        case 12:
            //change line color
            let cell = tableView.dequeueReusableCell(withIdentifier: "titleCells") as! titleCells
            cell.cellImg.image = iconImg[indexPath.row - 3]
            cell.cellName.text! = menuTitle[indexPath.row - 3]
            return cell
        case 13:
            let cell = tableView.dequeueReusableCell(withIdentifier: "titleCells") as! titleCells
            cell.cellImg.image = iconImg[indexPath.row - 3]
            cell.cellName.text! = menuTitle[indexPath.row - 3]
            return cell
        default:
            return defCell

    }

除了 switch 语句之外的任何提示或不同的方法都会有所帮助。提前致谢。

【问题讨论】:

    标签: ios swift menu swrevealviewcontroller


    【解决方案1】:

    问题在于,当您进入任何 switch case 并出列cell 时,defCell 中已经有另一个单元格出列。我过去遇到过麻烦。我不知道为什么,但由于某种原因,它弄乱了 tableView。解决它的一种方法是做这样的事情

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            let cell = tableView.dequeueReusableCell(withIdentifier: "profileCell") as! profileCell
            cell.nameLbl.text = "Name Here"   //need to pull name from the database here
            cell.profileImg.image = UIImage(named: "face")! //pull from db
            print(cell)
            return cell
        } else if indexPath.row == 1 || indexPath.row == 5 {
            let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell") as! labelCell
            if indexPath.row == 1 {
                cell.menuLabel.text = "For Sale"
            } else {
                cell.menuLabel.text = "Profile"
            }
            return cell
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "titleCells") as! titleCells
            if indexPath.row <= 4 {
                cell.cellImg.image = iconImg[indexPath.row - 2]
                cell.cellName.text! = menuTitle[indexPath.row - 2]
            } else {
                cell.cellImg.image = iconImg[indexPath.row - 3]
                cell.cellName.text! = menuTitle[indexPath.row - 3]
            }
            return cell
        }
    }
    

    如您所见,使用这种方法,一次出队的单元格不会超过一个

    【讨论】:

    • 你是个巫师。谢谢!
    • 很高兴为您提供帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多