不能让斯威夫特在我的视图控制器上的后退按钮

问题描述 投票:0回答:4

这里是发生了什么:

我有导航控制器与A-TableViewController设定为根视图控制器。当我点击在一个细胞时,它会带我到B视图控制器。导航控制器有一个标识符“MessagesViewController”。这里是我的代码迄今在A-TableViewController:

func tableView (tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let sb = UIStoryboard(name: "Main", bundle: nil)
    let messagesVC = sb.instantiateViewControllerWithIdentifier("MessagesViewController") as! MessagesViewController
    //Some code here
    //This has a back button, but nothing else
    self.navigationController?.pushViewController(messagesVC, animated: true)
    //This has no back button, but everything else that I intended works
    self.navigationController?.presentViewController(messagesVC, animated: true, completion: nil)

我希望能够回到A-TableViewController的一切工作。是不是我推/呈现多数民众赞成搞乱它的视图控制器的方式吗?任何人有任何线索,为什么我一直停留在此为近3天呢?

ios swift uinavigationcontroller
4个回答
1
投票

你得到建于后退按钮,当你推到一个导航图的图。该presentViewController有模式地显示你的看法。我已经在过去做的是添加自己的后退按钮的观点和出示。然后,当你按下它,你打电话dismissViewController。


0
投票

您可以使用prepareForSegue方法来传递数据,是这样的:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if segue.identifier == "messageSegue" {
        let vc:  B-ViewController = segue.destinationViewController as!  B-ViewController
        //then set properties of your new viewController like this
        vc.property = dataToPass
    }
}

0
投票

如果你确实使用导航控制器,比你的问题应该是很简单的。创建@IBAction,并在它,调用popToRootViewControllerAnimated,就像这样:

 @IBAction func rootButton(sender: UIButton) {
    navigationController?.popToRootViewControllerAnimated(true) // or false :)

}

0
投票

呈现你的后B-视图控制器试试这个在viewDidLoad中:

let btnBack = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(dismissVC))
    btnBack.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black], for: .normal)
    navigationItem.setLeftBarButton(btnBack, animated: true)

@objc func dismissVC() {
    self.dismiss(animated: true, completion: nil)
}
© www.soinside.com 2019 - 2024. All rights reserved.