2017-09-04 143 views
2

非常简单的情况下,有很多这个帖子,但我仍然坚持。我有一个嵌入在UINavigationController中的UITableView最终UIViewController应该在选择UITableViewCell时显示。当我将所有这些连接起来时,行选择上没有任何反应。UINavigationController没有后退按钮

我可以得到详细视图,由我们的didSelectRowAtIndexPath呈现,并通过它的id引用segue。但是,当我这样做时没有后退按钮。

enter image description here

enter image description here 类MainViewController:UIViewController的,的UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var tableview: UITableView! 
    var configJson: JSON = [] 
    var config: [Tab] = [] 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     parseConfig() 
    } 

    func parseConfig() { 
     let configParser = ConfigParser(configJson: configJson) 
     config = configParser.parse() 
    } 

    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return self.config.count 
    } 

    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let tab = self.config[indexPath.row] 

     let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell") 

     cell.textLabel?.text = tab.title 

     return cell 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     performSegue(withIdentifier: "contentSegue", sender: self) 
    } 

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

     if (segue.identifier == "contentSegue") { 
      let nextVC = segue.destination as? ContentViewController 
      let indexPath = self.tableview.indexPathForSelectedRow 
      let tab = self.config[(indexPath?.row)!] 
      nextVC?.tab = tab 
     } 
    } 
} 

一对夫妇的其他注意事项:1。 我IDENTIFER细胞在IB
设置为 '细胞' 2.我的segue在IB
中设置为'show',标识符为'contentSegue'3. Segue从原型单元格到内容Vi新的控制器。

我完全失败。谁能帮忙?谢谢。

+0

请提供您的下一个视图控制器代码 –

+0

没有任何呢。这只是一个空的viewDidLoad()方法。 – Alex

+0

尝试删除你的segue并重新创建它,有时它是有帮助的,也许你从UITabeView或Cell创建它,而不是ViewController –

回答

0

您确定您已将此设置为选择继续,而不是辅助操作?您可以通过点击故事板中的单元格来检查这一点 - 确保触发的Segue是选择。

也...

正如你所添加的SEGUE在你的故事板,有没有必要启动它在didSelectRowAt - 这样你就可以删除FUNC。

而且,为了删除您依赖于字符串比较(和取出力解开可选),试试这个...

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if let nextVC = segue.destination as? ContentViewController, 
     let cell = sender? as UITableViewCell, 
     let indexPath = tableview.indexPath(for: cell) { 

     let tab = self.config[indexPath.row] 
     nextVC.tab = tab 
    } 
} 
+0

感谢您的回复。是的,这是一个选择赛。我编辑了我的帖子。另外,我知道我不应该需要didSelectRowAt,但是我添加了它,因为我的点击事件没有注册。我希望能够完全删除它。 – Alex

+0

更多的评论序列比答案... – matt

相关问题