0

from a dynamic tableView "CardSets" I do a segue to a static tableView "AddCardSet" to enter some data. After successfull save() method I want to send the user back to the initial tableView "CardSets". How can I do that?

Do I have to set a segue onto the save button? Or is there a shorter way?

user1555112
  • 1,897
  • 6
  • 24
  • 43

3 Answers3

8

You can use popViewControllerAnimated:

if let navigationController = self.navigationController
{
    navigationController.popViewControllerAnimated(true)
}
Sebastian
  • 8,046
  • 2
  • 34
  • 58
  • this works for me! Thanks! One further question, how do I force the tableView "CardSets" to reload at the moment I return? – user1555112 Mar 05 '15 at 14:07
  • You can overload `viewWillAppear` in in the other view controller. This is called whenever the view is added to the hierarchy. – Sebastian Mar 05 '15 at 14:13
  • like this? `override func viewWillAppear(animated: Bool) { self.tableView.reloadData() }` It wont work for me :( there is no reload – user1555112 Mar 05 '15 at 15:14
  • Hm, is it called at all? And don't forget to call `super.viewWillAppear(animated)`. Have also a look at [I need to refresh the content of a view as soon as I popViewController](http://stackoverflow.com/q/2597421/172695) – Sebastian Mar 06 '15 at 08:14
1

the best answer is to create A singltone like this :

for example :

class Collage {

var classes: [Class] = []
static var collageSharedInsttance : Collage? = nil

static func GetSharedInstance() -> Collage {
    if collageSharedInsttance == nil {
        collageSharedInsttance = Collage()
    }

    return collageSharedInsttance!
}

}

and Access your data from the second controller like this :

    var JohnBryceCollage = Collage.GetSharedInstance()
danny
  • 147
  • 1
  • 15
-1

The best option is to use Unwind segue for this case. They allow you to jump back through navigation stack. And they are independent of how your controllers are presented - modally or within UINavigationController stack. More of that they allow you to jump through multiple levels back.

Please check out Apple's Tech Note and this great answer

Community
  • 1
  • 1
Max Komarychev
  • 2,836
  • 1
  • 21
  • 32