【发布时间】:2016-03-06 07:57:21
【问题描述】:
问题: 如果用户“登录”我想在单元格中显示“注销”选项,反之亦然。但我 在 Storyboard 中创建 UI 为
我已经创建了自定义 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!
}
但我得到了零单元格。我设置了数据源、委托、表连接。如何解决?
【问题讨论】:
-
能否显示错误报告
-
只是“在展开可选时意外发现 nil”
-
让单元格:UITableViewCell? = menuListView.cellForRowAtIndexPath(indexPath)
-
我无法从 interfacebilder 获取单元格,因为我没有将自定义类设置为单元格,因为它在 SWRevealViewcontroller 中不需要。所以得到零单元格。
标签: ios swift swrevealviewcontroller