Xcode Swift回到上一个viewController(TableViewController)

在我的TableviewController中,我有一个右上angular的栏button项目。 点击button后,会显示一个新的视图控制器。 在这个控制器中,我input一些数据到文本框并保存。 为了保存这些数据,我必须点击一个button,这也是一个右上angular的酒吧button项目。

但现在它委托我到我的应用程序的第一个视图控制器。 我做了什么,它委托我回到表视图控制器?

编辑:

当我使用下面的代码,该应用程序给我一个EXC_Breakpoint: (code=IEXC_386..)的错误EXC_Breakpoint: (code=IEXC_386..) ,它去视图控制器TeamOverviewController

 var vc = self.storyboard?.instantiateViewControllerWithIdentifier("TeamOverviewController") as ViewController self.navigationController?.popToViewController(vc, animated: true) 

看来解决scheme可以使用一个标准的“放松继续”。 在这个问题上有很多post,但是我总结了一个希望类似于你的问题的方法。

  1. 我使用了一个名为“Next”的右上angular有一个栏button的TableViewController。 当单击“下一步”时,将显示一个ViewController,您可以在其中放置任何input控件。
  2. ViewController的右上angular还有一个“保存”button。
  3. 两个控制器都embedded在NavigationControllers中以方便导航
  4. 当保存button被点击时,保存你需要保存的任何数据后,它将返回到TableViewController。
  5. 在TableViewController中,您需要添加一个名为unwindToThisViewController的IBAction函数。当您触摸ViewController中的“保存”button时,这是您指向的位置
  6. 在ViewController中,您需要将Ctrl从“保存”button拖动到“退出”图标(ViewController Storyboard中的第三个图标)。 当你这样做,你会得到一个名为unwindToThisViewController的下拉选项作为你应该select的呈现segue。 现在你的ViewController被连接到unwind segue进程。
  7. 在ViewController中,不要为保存button放置一个IBActon。 而是把你的保存命令放在函数prepareForSegue中。

这里是2个控制器的代码:

  // // TableViewController.swift import UIKit class TableViewController: UITableViewController { // add this function. When the detail ViewController is unwound, it executes this // function @IBAction func unwindToThisViewController(segue: UIStoryboardSegue) { println("Returned from detail screen") } override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // Return the number of sections. return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // Return the number of rows in the section. return 3 } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell // Configure the cell... cell.textLabel!.text = "Row: \(indexPath.row)" return cell } } // // ViewController.swift // Detail View import UIKit class ViewController: UIViewController { // When Save button is clicked, view controller is segued to the TableViewController to the function // unwindToThisViewController override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Insert your save data statements in this function println("Insert your save data statements in this function") } } 

如果你使用UINavigationController你可以直接popupviewController你需要什么。

例如: [self.navigationController popToViewController:TableViewController animated:YES];