0

I have simple app. My tableViews contains some words; I post data in post screen and I want to get back to the first tableView screen. I have use a segue for this. The problem is that each time after posting, clicking the post button opens a new tableView over the post screen. I want to return to the original.

Table View Screen -> Post Screen -> New Table View Screen

But I want

Table Vievscreen <-> Post Screen

Prune
  • 76,765
  • 14
  • 60
  • 81
JRdsdUY
  • 1
  • 1
  • Are you looking for `self.navigationController.popViewControllerAnimated(true)`? – JAL Apr 25 '16 at 18:50
  • I think my problem is similar to that one: http://stackoverflow.com/questions/26337304/view-appearing-twice-when-performing-segue – JRdsdUY Apr 25 '16 at 18:55
  • Use an unwind segue - http://stackoverflow.com/questions/36824524/programmatically-defining-a-new-navigation-controller-order-stack/36829034#36829034 – Paulw11 Apr 25 '16 at 20:21
  • Fixed grammar; cleaned up word flow a little. – Prune Apr 27 '16 at 21:31

4 Answers4

1

I had the same issue.It is resolved now. Please let me know if this helps.

I already have a segue linked from table view cell to another view with name DynamicSuperView

func tableView(_tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{
//Remove the below line from this function as it will perform segue.
//performSegue(withIdentifier: "DynamicSegue", sender: self)
}


override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?)     {
// This will actually perform your segue
var DestViewController = segue.destination as! DynamicSuperView 
let selectedRow = tableView.indexPathForSelectedRow?.row
 DestViewController.labelText = names[selectedRow!]
}

Hope this helps to somebody.

DEV
  • 949
  • 1
  • 9
  • 29
0

We need a LOT more information to what is provided. However this may get you started in the right way.

If you are using a navigation controller, put this in your posting view code:

navigationController!.popViewControllerAnimated(true)

If you are NOT using navigationController but instead showing the view modally, then use the following in your posting view code:

dismissViewControllerAnimated(true, completion: nil)
oyalhi
  • 3,834
  • 4
  • 40
  • 45
  • I am using navigation controller, I tried it now it is like `Table View -> Table View` after posting the data. If I delete popViewController it is like, `Table View Screen -> Post Screen -> New Table View Screen` – JRdsdUY Apr 25 '16 at 19:00
  • You have 2 view controllers, one with the tableView the other with some post data. In your view controller where the post data is. Please copy / paste your code to where you are dismissing the view controller. – oyalhi Apr 25 '16 at 19:12
  • sure but I create segue by right clicking the button and creating action segue "show", therefore there is nothing in the code related with the segue. – JRdsdUY Apr 25 '16 at 19:34
  • I am interested in the other view controller code. What do you code to get back to the main window? What code does the "Post Screen" have to get back to the "Table View Screen"? You need to have a code like this: `navigationController!.popViewControllerAnimated(true)` – oyalhi Apr 25 '16 at 19:34
0

Most segues create a new instance of a view controller and display it on top of existing view controllers.

If you are adding a view controller to a navigation stack with a push, you want to do a pop as described in JAL's comment.

If your segue is modal, you want to do a dismissViewController:animated:

You could also set up an unwind segue, although that might be overkill for this simple case.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

I'm getting the same issue here, but I realize that I just did wrong on control+click, I dragged from cell, the correct must be from tableview

I hope this help some one

Daniel Beltrami
  • 756
  • 9
  • 22