在 swift 中处理 SWRevealViewController 中的 CellForRowAtIndexPath?

Handle CellForRowAtIndexPath in SWRevealViewController in swift?

问题: 如果用户 "Login" 我想在单元格中显示 "Logout" 选项,反之亦然。但我 在 Storyboard 中创建了 UI 作为

我创建了自定义 UITableView class 和 cellForRowAtIndexPath 看起来像

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

  //  var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell!

     let cell : UITableViewCell? = menuListView.cellForRowAtIndexPath(indexPath)

    if indexPath.row == 20
    {
        let titleLabel = cell?.contentView.viewWithTag(100) as! UILabel
        if(NSUserDefaults.standardUserDefaults().integerForKey("UserID") <= 0 ){
            //logout
               cell?.contentView.backgroundColor = UIColor(red: 6.0/255, green: 46.0/255, blue: 107.0/255, alpha: 1.0)
               titleLabel.text = "Login"
        }else{
                //user is login
                cell?.contentView.backgroundColor = UIColor.redColor()
                titleLabel.text = "Logout"
        }
    }

    return cell!

}

但我得到的是零单元格。我设置 Datasource,Delegate,table connection.How 来解决这个问题?

已使用以下代码修复。使用 tableviews 委托方法 willDisplayCell。

 override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

            if indexPath.row == 20
            {
                let titleLabel = cell.contentView.viewWithTag(100) as! UILabel
                if(NSUserDefaults.standardUserDefaults().integerForKey("UserID") <= 0 ){
                    //logout
                    cell.contentView.backgroundColor = UIColor(red: 6.0/255, green: 46.0/255, blue: 107.0/255, alpha: 1.0)
                    titleLabel.text = "Login"
                }else{
                    //user is login
                    cell.contentView.backgroundColor = UIColor.redColor()
                    titleLabel.text = "Logout"
                }
            }

    }