gpt4 book ai didi

ios - 快速处理 SWRevealViewController 中的 CellForRowAtIndexPath?

转载 作者:行者123 更新时间:2023-11-30 13:38:37 25 4
gpt4 key购买 nike

问题:如果用户“登录”,我想在单元格中显示“注销”选项,反之亦然。但我在 Storyboard 中创建了 UI

enter image description here

我创建了自定义 UITableView 类和 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!

}

但我的细胞为零。我设置了数据源、委托(delegate)、表连接。如何解决这个问题?

最佳答案

使用以下代码修复。使用tableviews委托(delegate)方法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"
}
}

}

关于ios - 快速处理 SWRevealViewController 中的 CellForRowAtIndexPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35824486/

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