iOS 7 - Maintain view controller instance in Storyboard segue - ios

I have an interactive custom view controller transition based on a storyboard segue (push).
The target view controller takes some time to be loaded as it contains a table with a lot of data; moreover when I leave this vc and come back, I need the table to maintain its content offset and not to start each time from the first row.
In order to achieve these two points I need the target vc to be a kind of singleton, and not to be deallocated/reallocated every time.
Any suggestion?
Thanks,
DAN

Don't use a segue -- they always instantiate new view controllers. Create a property for the destination view controller in the controller that initiates the transition, and only instantiate it the first time you go to it. Push the new controller in code.

Related

UINavigationController for infinite navigation (nested folders)

I need to navigate inside folders and files in directory (from server). The problem is that I don't know the number of folders so it's not possible to use performSegueWithIdentifier statically. How can I use navigation controller with dynamically number of view controllers in swift? I want to "push" a new view controller every time a user tap on a folder in order to list files/folders inside it and I want to do it with UINavigationController so the user have the possibility to go back with "previous" button.
Both storyboard and programmatically approaches are ok.
Thanks you
Storyboards and segues are just a crutch. Think about how you would do this without them. At each level, to go down a level, you would just instantiate a new view controller and push it onto the navigation controller stack with pushViewController:animated:.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/#//apple_ref/occ/instm/UINavigationController/pushViewController:animated:
And in fact it takes only one view controller class to do this, since any instance can create and push another instance of its own class. The display of one folder is exactly like the display of any other.
So if you wanted to configure this notion in a storyboard, you would have a circular segue, that is, the view controller would have a push / show segue leading to itself.
I agree with #matt's answer, just create the controller and push it. For sake of completeness, you can do this in a Storyboard with a segue.
Here's how:
So that you can call the segue programmatically, add an additional prototype cell to your tableView. (You do this because you don't want the segue to be automatically triggered when the tableViewCell is selected. By using an additional prototype cell, the segue can be wired up, but it will never be triggered automatically since this prototype cell will never actually be instantiated.)
Control-drag from this prototype cell to the viewController icon at the top of the tableViewController. Select "Show" from the pop-up.
Find this segue in the Document Outline View and give it an identifier such as "showFolderSegue" in the Attributes Inspector.
Now, when you want to trigger the segue, call: self.performSegueWithIdentifier("showFolderSegue", sender: self)
You can use prepareForSegue to set up the new tableViewController as you normally would.
This method too works with a single tableViewController.

custom container view controller vs normal segue and rewind segues

My intent was to create a master scene and view controller that was in control most of the time, but when logic demanded it would segue to one of several other scenes. Each of these "other" scenes would return to the master view controller using rewind segues. Which other scene was chosen was determined by logic in the master view controller. This worked fine until I found a need to transition from one of the "other" scenes to a different "other" scene without presenting anything from the master scene. I want to put a performSegueWithIdentifier in the master view controller before anything is presented.
I have tried putting the performSegue.. in the method that catches the rewind segue, in the viewWillAppear method, in a block kicked off async from the rewind method, but in all cases I see the performSegueWithIdenitifer method execute, then the appropriate prepareForSegue but then control returns to the master view controller and the scene I get in the device is from the master view controller.
I tried to look at other methods and it would seem that building a custom container view controller is one way of doing this, but it does not seem right since all the "other" scenes I want to segue to are push segues and take over the entire screen.
Is there some reason that a view controller that has received control from a rewind segue cannot then kickoff a segue without ever appearing itself? Is the Custom container view controller the correct way to do this? And if the latter, do I let the storyboard set up the embed segues to all the other view controllers, or do I leave them unconnected in the storyboard and load them in code?
Thanks in advance, ##warning - novice here - this is my first real project##

How to save values in view controllers during app running? ios7

I got app with 2 view controllers, I'm typing values via NSStrings in Label and TextField in my first view controller and when I by pushing my navigation button go to my second view controller.
When I return to my first view controller, I got entered early values. But when next after that I go to my second view controller - values entered via NSStrings in Label and TextField disappear. How to fix this that the values ​​saved?
I tried to use strong and copy properties but that not helps me.
UPDATE
I use segue and storyboards, segue with modal type, I use 2 navigation controllers: for first view controller and for second. I got code only for modal type. First view controller is root for navigation
UPDATE
I use 2 navigation controllers because I need modal segue from first VC to second and from second to first, when I use one navigation controllers that is not works like I need
Post some code otherwise we are just guessing. One guess is that you are using segues. Segues always create a new instance of the viewController. If you don't hold on to the old viewController somehow, it will get destroyed and any values it contained are also gone.
Just a guess.

How to find the name of the view controller beneath a popover ios7

This is probably a very simple question but I can't find the answer to it.
I am working on a new project that uses Storyboards for the first time.
I have a number of view controllers that connect the way I want them to.
Each view controller has an info button.
I have one view controller (AboutViewController) that I want to use to display the info for all the view controllers. I am currently calling this via a popover segue from each screen. So I have one destination view controller (AVC) that I am calling from a number of VCs- VC1toAVC, VC2toAVC, VC3toAVC etc. I want two textfields in AVC to change, depending on which VC called it.
So here's the problem- how can I tell which view controller called the popup? It's basically the view that's below the popover. Currently I'm storing it as a variable but that's not ideal. I'm guessing it has something to do with the segue identifiers?
Any and all help much appreciated!
One approach to this is adding a property to your pop up view controller and then define the
prepareForSegue:sender:
method so you set your destination view controller's property to the sender of the segue.

Solving errors in view transitions (storyboards)

I'm developing an application that works with 2 different views. Today I noticed that every time I step from view 1 to view 2 the app creates a new view.
And when I return to the previous view it simply creates a new instance of view1, ie it creates a new view in memory. (and keep the previous)
I would like to use the same view without creating a new instance (a new view in memory) each time the user passes a view to another.
I would like transit between just the 2 views that I created.
Note: I'm using the iOS 6 with Storyboard and ARC. And the transition is made by a tap gesture recognizer. Once I tap the view it goes to the next view using a modal transition.
When you go from view controller 1 to view controller 2 as a modal (presented) view controller, you use a modal segue. This will indeed create a new instance of view controller 2. When you go back, in iOS 6, you must use an unwind segue to the first view controller. This will cause the view controller 2 to go out of existence, and it will use the existing view controller 1, not create a new view controller 1.
Here's my explanation of unwind segues.
http://www.apeth.com/iOSBook/ch19.html#_unwind_segues
(Either that, or don't use a segue at all; just call dismissViewController yourself, as we did in iOS 5 before unwind segues existed. Or don't use a storyboard in the first place; they really aren't necessary. Here's my explanation of presented ["modal"] view controllers: http://www.apeth.com/iOSBook/ch19.html#_presented_view_controller)

Resources