how to avoid circular segues in swift - ios

I have a project which has the following structure:
The user is presented with a login view controller, on successful login, a tab group is opened. One of the tabs is a profile tab. From within there, a user can click on a following or followers button.
Each of these buttons segue onto a list of users. From there each user is clickable and this leads onto a 'membersDetailed' controller. Within that controller, there is again a followers and following button. This again is clickable and leads to a list of users who are then clickable leading back to 'membersDetailed' again. So with the current set up, the user can keep going further and further in and memory is a concern for me.
How can I handle this is the most memory efficient way? Should I be programmatically popping controllers instead of using storyboard segues or what is the best approach?
I'm also noticing that when I navigate back along the chain the memory doesn't seem to reduce. Even though I am using a navigation controller.
Any help appreciated.

You can use Unwind Segue to go back or on the reverse direction

Related

Walkthrough with tab view controller

I have been attempting to create a walkthrough for my app although I also have a tab view controller which is the initial view controller. I have been able to identify when a user is opening the app for the first time, but when I make the walkthrough view controller initial, I get a Sigbart error. This is because I set up my tabbar in the app delegate.
Is there a way to possibly keep the tab bar VC the initial and hide the first VC if it is the users first time opening the app?
Is there another way of doing it?
I dont know the code to check of its the flrst time a user opens an app, but why dont you make that check on your tab bar controller? And then lf lt ls the first time, you just change the root vc to the tutorial vc. When they are done with the tutorial you just change back the root vc to the tab bar.
There easiest way to accomplish the tutorial-like behavior for new users is:
1) Make a new View Controller be the initial one.
2) Add code to check if its the first time the user launched the app. If it is, show the tutorial, if its not, show your tab view controller.
3) You can fill this "fake initial" view controller with the same image shown in the splash screen. This way the user will feel its just the splash one.
*) An added benefit of this approach is that you can check other useful things. For example, if your app has some kind of login feature you can manage it here skipping the login window for users who have already logged in. It can also be used to update your app's resources in case you are retrieving them from a server.

iOS navigation best practice for adding items

I cannot find the answer to this although I have implemented this rather a few times already, but maybe the wrong way.
Say I have an App for iOS, it has a main screen, which goes to a list, that list has a < back (to main) and an add button. Now when I click < back, I go back to main as that's the pop() from the stack. No issues so far.
Now when I click the add button, that is added to the stack as well; when I click back on that screen I go back to the list which is fine.
The problem is; when I save the new item, I want to go to the detail screen, but I don't actually want to have the add screen on the stack anymore while it will be there. I want the < back button for the detail item pointing to the list.
I know how to do this, but what is actually the best to implement this with the navigation stack?
Well for adding elements the best practice is to present an ModalViewController.
In this way it is not added to the stack.
Update
Let's take as examples simple apps that apple provide with iOS, Contacts app. When you want to add a new contact a VC is presented.
You'll need to implement "Done" or "Save" button that will dismiss the modalViewController and if you want to take the user into detail screen you could post a notification or other mechanism on dismissViewController method's completion block that will push the detail page from the list. But be careful on animations if you dismiss the modal VC animated and push the detail page animated you could get some unexpected behaviour. My proposal is to dismiss the Modal VC animated and push the detail page without animation.
You can override UINavigationController's viewControllers property after you pushed detail view controller. Just get current viewControllers property array, iterate and find the one you don't want to see and remove it. Remember to set viewControllers array again.
https://developer.apple.com/library/ios/documentation/Uikit/reference/UINavigationController_Class/index.html#//apple_ref/occ/instp/UINavigationController/viewControllers

iOS (ipad) split view controller

I have a couple views that come before I want to show my split view, disclaimer and then login. After successful login I want to segue to the the split view controller. However I do not think there is a way in storyboards to segue to a split view controller. How do I get from a normal view into my split view controller.
Sometimes if it seems to cumbersome it may be an indication that one need to look at the problem from a different angle.
Assuming your goal is that of forcing the user to go through the login process,
this is what I would do:
Have your splitView as the default view controller, added in the storyboard and loaded as the app starts
As soon as app is loaded, check for the existence of the user's credential. If you don't find any,
present your login framework modally (full screen to cover any data underneath).
Once the user has successfully logged it, dismiss the modalVC and you will have the underlying splitVC underneath ready for use.

Segue type to be used for a user registration process - iOS 5

This is my first ios app & I have a user registration process which is separated out into 3 screens. The first screen has user to enter his mobile number, the second screen asks him select his location & the third screen asks him to enter his birthday and a few other details.
So in total, there are totally 3 controllers which I have used.
1) mobile_number_controller.rb
2) location_controller.rb
3) miscellaneous_details_controller.rb
Each detail the user enters is validated and is stored into the NSUserDefaults. If the validation fails then the user is not allowed to move to the next screen. Also, once the user enters his details correctly, then the user does not have a back button to go back to the previous screen as well.
I would like to know which is the type of segue to be used here. Should I embed these controllers in a navigation controller and use a push segue, or should I be using a modal segue?
Update regarding the chain of controllers.
I don't intend to take the user back to any presenting controller at any stage. Also, in most code I have read till now, for modal segues, I have seen the presented controller being dismissed or there's an unwind segue to go back to the presented controller. I am a bit confused on what to do with these presented controller here before presenting the next controller in the series?
Also, as I mentioned that I store whatever data has been entered by the user in NSUserDefaults, theres no need for the presenting controller to know about the data entered in the presented controller. Hence I don't feel the need for an unwind segue( like in the 'new contacts' application).
Any help on this would be much appreciated.
I would prefer a modal segue to present a navigation controller and push segues to connect the other view controllers. Similar to webapps a user perhaps want to step back to change previously entered information.
I would use a series of modal segues (presented view controller). This is not a "user can go forward and back among views" situation: you are in total control of what the user sees. It is perfectly legal to present a view controller on top of a presented view controller. Moreover, it is simple to control how far back you take the user, e.g. go back all the way (dismissing all the views), if that's what you want to do.

How can I make one Tab Bar button refer to two views/controllers in iOS

I'm developing an iOS app just now with a Tab Bar navigation.
I have two screens which show the same information but in different formats (say, list and grid).
The two screens are different enough that they require separate controllers.
Users can toggle between the two views from a shared control bar button (toggle) at the top.
Scenario:
User presses the 'Places' button for the first time and it shows the places as a list.
They press 'grid' to see the same places displayed as a grid.
The user presses another tab bar button to navigate to a different screen.
When they press the "Places" button again, the app remembers their last viewed screen for places was the grid so the grid view is shown.
The user may then toggle back to list view. etc...
Can anybody recommend the best approach to achieving this?
One approach is to use one view controller that manages both views. That way, you don't have to bother with synchronizing data or subverting the normal function of UITabBarController -- there's just one controller. Also, don't try to overload the meaning of the tab for that controller. Instead, add a button to both views that tells the controller to switch to the other view. That'll be easier for your to build, and (more importantly) easier for the user to understand. It's not nice to make familiar controls do unfamiliar tricks.
If your view controllers are such that combining them into one would be complicated, then you can use two controllers and simply swap them in and out of the tab bar by modifying the tab bar controller's viewControllers array. You can still avoid having to sync data between them by having both controllers refer to the same data model.
I was trying to achieve this same thing, and it can actually be done with a basic setup of a TabBarController, NavigationControllers, ViewControllers, push segues, and unwinds.
TabBarController
|==> NavigationController --> PlacesController(grid view) --(push segue from nav bar)--> PlacesController(list view)
|==> NavigationController --> OtherController
|...
Make sure to have an unwind segue back from the list view controller to the grid view controller.
If you toggle between views then go to another tab (e.g. otherController) and come back, you'll return to the last view you were seeing because that's what is at the top of the stack of the NavigationController.

Resources