2016-02-16 49 views
0

我有一个静态单元格的表格视图(如下所示)。 enter image description hereDidSelectRowAtIndexPath不能在Swift 2.0中工作

显然,我希望我的应用程序在当前用户登出时登出。对于部分的数量,我有以下代码。

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     var rows: Int = 0 

     let numberOfRowsAtSection: [Int] = [2, 2, 1] 

     if section < numberOfRowsAtSection.count { 
      rows = numberOfRowsAtSection[section] 
     } 

     return rows 
    } 

我通常会做didSelectRowAtIndexPath来注销这个用户,所以我试了下面的代码。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

     if (indexPath.row) == 4 { 
      PFUser.logOut() 
      dismissViewControllerAnimated(true, completion: nil) 
     } 

    } 

它不工作,因为注销实际上是在索引0,所以当我单击编辑个人资料或关于它记录了我,因为有3个指标0的这么说。我不确定我是如何解决这个问题的,我试过上面的代码没有成功 - 有什么想法?

回答

3

重新写你的didSelectRowAtIndexPath如图所示:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

    if ((indexPath.section == 2) && (indexPath.row == 0)) { 
     PFUser.logOut() 
     dismissViewControllerAnimated(true, completion: nil) 
    } 
} 
1

检查科和行号

if indexPath.section == 2 && indexPath.row == 0 { 
    /* do log out */ 
}