Segues where a view replaces another - swift

I'm planning a game app where a series of views are presented, one after the other, sequentially, in a loop.
I'm having a hard time figuring out the segue I should use for this (using the storyboard). It seems to me, that using the 'show' segue will result in a stack of views. In my app, you never go back from where you came, so does that mean that I could end up with dozens of views, one on top of each other?
Is there a way so that once you go into a segue, one view replaces the previous view?

Unfortunately you are not going to be able to do this with Storyboard segues as the "Replace" segue is only for SplitViewController (which sounds like wouldn't be right for what you are trying to do). Instead handle transitions through code. Have a base navigation controller and keep setting the new view controllers as the navigation controller's root view controller

Related

Unwind segue results in black screen? UITabBarController with embedded VCs and segues

I have the following hierarchy for my app:
UITabBarController, first tab is a BrowseVC (another UIViewController). BrowseVC has a SegmentedControl, each of which will show a version of the PersonVC (another VC with a UICollectionView in the ContentView). They are each loaded with a lazy instantiation like this article. Tapping a cell in the PersonVC will show PersonDetailsVC via a modal segue.
I'm attempting to put a "Back" button on the PersonDetailsVC to get back to the PeopleVC collection view. I thought I'd have to put the unwind segue in the UITabBarController, however, while it is called just fine (a print statement shows it "works"), the view is black.
Using the Xcode view debugger, the PeopleVC is in the hierarchy on the left, but I've no idea where it is physically.
For this configuration, which VC should the unwind be located in? I've tried putting in the BrowseVC and the PeopleVC but it would seem logical that the TabBarController would need to reload all of the content? Is there a best practice for this scenario? I can't imagine this is very unique at all. What gotcha(s) might I be missing?
TIA!
Apparently it is the modal presentation that is killing the unwind capability. Other presentation methods work fine. Disappointing.

AdBannerView proper implementation to multiple view controllers

Currently have I implemented iAd and AdMob to each and every view controller in my Xcode project. I have about 6 view controllers and every time I switch back and forth between them one adbanner disappear and another appears. I want to make only one single adbanner for all view controllers. So even though its a transition between two view controllers, only one adbanner will be visible and it will not disappear and appear again.
But I also need to reach it from each class. So I can show it and hide it when I want to.
I would appreciate a ditailed step-by-step instruction.
INFO:
I am using storyboard. I am developing for iOS 6.0 and higher. I am using navigation controller.
So pass the banner view from one view controller to the next just as you'd pass any data. Install the view in the view hierarchy in each controller's -viewWillAppear method. You can pass the view between controllers in your -prepareForSegue method. If you're not sure how to pass objects between view controllers, search here -- here are many questions covering exactly that topic.

Objective - C How to manage multiple views with View Controller iphone

I am new in developing iOS apps. I am trying to develop a multiple views app. My doubt is how to manage a multiple views app with View Controller, I mean, I do not want to use Navigation Controller nor Tab Controller.
My idea is to show a first View to choose the language, and after this, I want to show some different profiles in a table view. When you choose the profile, you get into a menu where you have some different functionalities (Once in this menu, I might use Navigation Controller).
My problem is that I don't know how to manage these two first views. I don't know if I have to declare them in the appDelegate, or if I can do it nesting one to other, I mean, I do the first view, and when I pressed the button, I declare the new view. Once in the new view, when I pressed a row in the table view, I make the another view.
I know it is a little bit confusing, so I hope you could understand it quite well.
EDIT:
I want to clarify that I am not using storyboards. My main doubt is what to do with all de view controllers, Do I have to declare all of them in the appDelegate? or Can I declare each view in every controller?
If you are using storyboards, you can use Segue's to navigate between the views, so you would show your first view, then you could tie a button to the next view (by control dragging in storyboard). If you want to transition programmatically you can use the performSegueWithIdentifier method. You could use the same approach to get from your tableViewController to your next viewController by using the performSegueWithIdentifier method from within the tableViewController's didSelectRowAtIndexPath delegate method (i.e. when a user taps a cell).
That should get you started. Good luck!
EDIT:
You really should be using storyboards. It's the way to do things these days. If you refuse, then the best approach is to create a container view controller that manages your "children" view controllers. You can find information on doing this, as well as the methods needed to present/remove child view controllers here:
Custom Container View Controllers
You can use navigation controller with "hidden" property.
self.navController.navigationBarHidden = YES;
If you want to have two different views and transition between them, you will want to use UIViewControllers presented modally. Here is Apple's Guide to this.

Storyboard+Modal Segue + Memory

I have a storyboard with 6 View Controllers and their respective views. I do NOT have any navigation controllers associated with these 6 View Controllers.
To go from one view controller to another, the swipe gesture recognizer is used alongside a modal segue. All view controllers have alteast 1, and sometimes even two swipe gesture based modal segues to other view controllers.
My question is, do I need to worry about memory? When I swipe are these viewcontrollers going to be infinitely added to memory eventually causing the app to crash?
An example could be: Say I am in the first VC and I swipe Right to the second VC, then swipe once again to Right to Third VC, then swipe left twice to get back to the First VC will the memory contain this:
Memory: First VC, Second VC, Third VC, Another Copy of Second VC, Another copy of First VC?
I know it seems like a stupid question but since I have only started programming a couple days ago I am very worried I will be having memory issues.
I would appreciate your thoughts and any potentially helpful links to places that dicusses this issue.
you have a good question and it depends on how you are creating and dismissing your view controllers. Normally a design like you mentioned would be built using a built in controller like UINavigationController or UIPageViewController or maybe using a scrollview.
If you are "presenting" new view controllers, then you need to dismiss to remove them. If your not dismissing, then you view controllers will stick around.
If you are using segue's, remember that each segue creates a new instance.
If your logic generally says - swipe right: new modal segue, swipe left: dismiss, then you will be cleaning up as you go. This works if its ok that each right swipe creates a new instance.
If you need the six view controllers to stay in memory all the time, you may want to look at using a pageViewController or roll you own solution. I have seen some nice solutions like you describe using a scroll view.
If you wanted to use a scroll view, basically you would crete an array, load the array with the six instances of your view controllers, then load the scroll view for horizontal scrolling. Add the gesture recognizers and logic for left/right swipes and you have a nice horizontal page scroller.
Here is a very nice reference and tutorial that seems to solve the solution you are describing. http://www.wannabegeek.com/?p=168
good luck and happy new year.
As long as you dont keep strong references to the view (or its subviews, like buttons...), they will be deallocated if needed.

view controllers using storyboard

i am trying to switch between two view controllers using storyboard. I create a modal seague by control-dragging (on buttons) from 1st view controller to 2nd, and then from the 2nd to the first.
So whenever I click on a button in 1st VC, it takes me to the 2nd VC. This time when i click the button on second VC, does it take me back to the original instance of the 1st VC or it creates a new instance?
If it takes me to the same instance, and user had written some data in some textfields, is there anyway to retain that on screen? (I might want to save them in some variables, and since the program will return back to the same instancem i'll be able to get the variables back)
If it doesn't take me to the same instance, is there any method to do so?
I tried making an instance of 2nd VC and using self.navigarionController push...(instance) but this doesn't swtich the controller.
If i do this pushing using the storyboard, and i do pop in my 2nd VC, it doesn't get popped either.
(and i would also couldn't understand the difference between push,modal and custom seagues)
Create the modal segue from VC1's button to VC2, but not the reverse one. When the VC2's button is tapped, call dismissViewControllerAnimated:completion: to return to where you were.
If you used a push segue instead, you would call popViewControllerAnimated: to go back but that only works if you have your view controllers managed by a UINavigationController.
You can think of push as a way of stepping through a sequence of related scenes while modal is something that's a bit out of the normal flow of the application. (That's not a firm rule but it's a starting point for deciding which way to go.) For 'custom', you write the segue code, so you decide what happens.