2016-03-06 3 views
0

Проблема: ЕСЛИ Пользователь «Войти», я хочу показать «Выход» в ячейке и наоборот. но я создал пользовательский интерфейс в раскадровке вРучка CellForRowAtIndexPath в SWRevealViewController в swift?

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! 

} 

, но я получаю ноль ячейки. я устанавливаю Datasource, Delegate, table connection.How, чтобы исправить это?

+0

вы можете показать ошибку reprt –

+0

Just «» неожиданно обнаружил ноль, а разворачивание опция» –

+0

, в котором линия братан –

ответ

0

Исправлен с использованием следующего кода. использовать метод делегатов 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" 
       } 
      } 

    } 
Смежные вопросы