Share a view across multiple view controller - ios

Is there a way to share a view across multiple view controller? This is for making a cheat console for my app, and that console UI should be available through out all the view controllers.
Thanks in advance.

You can create a xib file with your view, then create a class and specify this class in the view file's owner. Then you can create outlets from the xib to the class.
And then follow this article to initialise and use the view:
http://onedayitwillmake.com/blog/2013/07/ios-creating-reusable-uiviews-with-storyboard/

Instead of a view, perhaps you may want to expand what you can do with your cheat console, and instead create a seperate view controller for your cheat console, then you have your other view controllers call it as a pop over. If you are doing it though UIBuilder, when you create the segue, you would set is as Present As Popover

Related

Is it possible to add the same view to two different view controllers?

I get the following error message:
A view can only be associated with at most one view controller at a
time!
Is it possible to add the same view to two different view controllers?
I want to add one instance of a Google Map to a Tab View Controller.
I'm using swift4 with the storyboards.
If it were a typical view then you should create an XIB and add a new instance of it to each view.
Since you're using GMSMapView from the Google Maps SDK, and you want to have the same instance across multiple tabs the approach will be different.
You can either:
New Instance, Same Parameters:
Create a new instance in each tab with the parameters set to be the same as the other tabs.
Move Around the Single Instance:
Create an instance of GMSMapView. Store it in a shared property. Use addSubview() to move it around. Basically use addSubview() in the new tab to remove it from the old one and add it to the new one.
A UIView can only be associated with one other view, because it can only have one parent view, which is set as the superView property. Also things like layout are set on this view and are relative to it's superview, so it makes no sense to use the same view in multiple Controllers.
The best solution would be to subclass UIView and then add new instances of your custom class to every ViewController

Adding a UICollectionViewController inside another UICollectionViewController

I am writing a project where I need to display a list of players (avatars) in a horizontal collection view controller / list, let's call this a HUD.
I want this HUD to be common, that is to say: I know this one component will repeat many times throughout the app.
I do not want to write the Collection View code over and over again.
I want to add the collection view to an existing view controller which already has a collection view.
Almost like an in-line Master-detail display where the master does not change from page to page.
Is there a way in Swift where I can instantiate the HUD collection View and append it to whatever View Controller I am in.
I have included a picture.
Thus my query is this:
How do I include a collection view controller inside another View controller that already has a UICollectionViewController?
How do I share this HUD component across multiple screens in the app?
Many thanks
I used a container view to solve my issue. This issue is now closed.

How can I link an outlet from a view controller to an other?

I am working on an app that uses parse so I used the "starter project" as a base and worked from there.
The issue I am facing is that the ViewController is controlling the login screen a well as others such as the tableView and mapView witch I added later.
As this is the case if it would be possible I would link the map outlet by simply dragging from the code to the map but obviously this is not possible, How could I solve this problem (I understand I may be looking at the problem the wrong way but any help would be appreciated)
here is the code with the map outlet
here is what the layout looks like
The MVC model, Model-View-Controller model, isn't intended to have an action in one view touch the controller of another view. In InterfaceBuilder, you should only ever be able to attach actions to the controller for that specific view.
In general, if you set the file owner to ViewController, then you can only link IBoutlets to that view controller not make to another one.
your map is available in your MapViewController not ViewController, so you need to give the reference/IBoutlet of map need to assign the MapViewController, if you want to implement in ViewController, you need to create new one map
No you have to create different file for each controller.
you cant add outlet of all in one controller

Best practice to develop common header view across all controllers/windows in iOS app

I'm keeping on developing an iPhone app (rigth now native one) and I would need to use a common "header" for all views but I don't want/need a UINavigationBar and prefer much more have a common "partial view". It will have some actions to perform but always the same ones (showing notifications panel, basically). It should be something like you can see in the screenshots.
I don't need (I feel) delegation because the controller's view can handle notifications and show them when user clicked the customize button.
I don't mind to use a Nib o make the view hardcoded but I'm not sure how I must make an instance of the view or the controller that handles it within each app tab (I'm using UITabBar as navigation control).
From my point of view it doesn't exist a way to get a common controller to call wherever needed; you just can use some method to present new controller as modal o push it out and I think that is not what I'm looking for.
Any idea is welcome. Thanks
Create a custom view controller with 2 subviews. Subview 1 is the header. Subview 2 is the container view where child view controllers are displayed (your tab bar controller in this case).
Your custom view controller could be the delegate of the tab bar controller if you want, so it can be notified when the tabs change and update anything on the header view.
Well, finally is have used the solution I found on the link http://patientprogrammer.wordpress.com/2012/03/12/re-usable-subviews-in-ios/
I have created a Nib with a view controller and then, in the main window I have added two view, the top one subclasses the view controller for the Nib view and it is rendered automatically when app is launched without a single line of code within "main" controller. See the screenshots for more detail:
Thank you very much for your help

iOS: Container View Controller Pattern

I'm having a bit of trouble wrapping my head around the way a container view controller is meant to be implemented.
I dragged a container into my main view controller and it automatically creates the embedded view controller and is connected via an embed segue. I can then access it from my main view controller via prepareForSegue.
I'm a bit confused as to creating and using these on the fly. Ie say I want to use it as an alert view. Am I meant to just initialize the view once, and then change its contents each time the display is meant to be triggered? Should I be calling presentViewController or just setting hidden/animating the view in and out?
Having trouble articulating. Hopefully someone speaks newb and can understand me.
Using an embedded controller that you get with a container view is not a good fit for something like an alert. You can't create these "on the fly" this way, since that embedded controller is instantiated at the same time as the controller it's contained in (you don't president it). You can do the same thing in code as what a container view gives you using the custom container controller procedures (see Apple's "Creating Custom Container View Controllers" document). If you just want to make a custom alert view like view, I would just create a custom view and add it as a subview to your controller.
Use setHidden: method when you want to show or hide that view.
[_myAlertView setHidden:YES];
[_myAlertView setHidden:NO];
I hope that I understood your question correctly.

Resources