Ios SWOVERVALVIEWCONTROLLER中SWOVERVALVIEWCONTROLLER中的ROWATINDEXPATH处理单元格?
问题: 如果用户“登录”,则在单元格中显示“注销”选项,反之亦然。但是我在故事板中创建了用户界面 我已经创建了自定义UITableView类和cellForRowAtIndexPathIos SWOVERVALVIEWCONTROLLER中SWOVERVALVIEWCONTROLLER中的ROWATINDEXPATH处理单元格?,ios,swift,swrevealviewcontroller,Ios,Swift,Swrevealviewcontroller,问题: 如果用户“登录”,则在单元格中显示“注销”选项,反之亦然。但是我在故事板中创建了用户界面 我已经创建了自定义UITableView类和cellForRowAtIndexPath override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // var cell : UITableViewCell? =
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!
}
override func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{
//变量单元格:UITableViewCell?=tableView.dequeueReusableCellWithIdentifier(“单元格”)为!UITableViewCell!
let单元格:UITableViewCell?=menuListView.CellForRowatineXpath(indexPath)
如果indexath.row==20
{
设titleLabel=cell?.contentView.viewWithTag(100)为!UILabel
if(NSUserDefaults.standardUserDefaults().IntegerWorkey(“UserID”)通过使用以下代码修复。使用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"
}
}
}
override func tableView(tableView:UITableView,willDisplayCell:UITableViewCell,forRowAtIndexPath-indepath:nsindepath){
如果indexath.row==20
{
设titleLabel=cell.contentView.viewWithTag(100)为!UILabel
如果(NSUserDefaults.standardUserDefaults().IntegerWorkery(“用户ID”),您能否显示错误reprtJust“在展开可选文件时意外发现零”let cell:UITableViewCell?=menuListView.cellForRowAtIndexPath(indexPath)我无法从InterfaceBiler中获取单元格,因为我没有将自定义类设置为单元格,因为它在SWRevealViewcontroller中不需要。所以获取nil单元格。