IOS Why does a view have 2 Custom Classes? - ios

Probably quite a simple question but I have not seen it addressed so far (I am a ios newbie)
So I start Xcode and create a simple (leave it Blank) view controller in Storyboard.
Click at the bottom so that it highlights in blue allows me to assign that view to a Controller that I am creating.
Thats found under the Custom Class field in xcode
Now if I click anywhere inside that blank view I see that Custom Class reference has changed.
Its now reffering to something else and not my Custom Controller that it was just pointing to.
What is this custom Class a reference to ?
What do I need to use if for ?
Does my view have 2 custom classes associated to it ??
Anyway as you can see I am confused by this.
Thanks !

When you click inside the controller, you're clicking on the controller's view, not the controller itself, so you're seeing its class (which should be UIView if you haven't changed it).

Related

How do I add code to my viewcontroller.swift for views connected via a navigation controller?

So I am pretty new to Xcode (but not programming in general, have learned a bit of python and java) and I am trying to figure out, for the life of me, how I connect bits of code in other views besides the first one when they are linked from a navigation controller.
To paint a picture of this, I essentially start out with a single view application, I have the first view and I add a button to it and then I embed it in a navigation controller by doing.. Editor -> Embed In -> Navigation Controller. The next time, as I have been following from various guides online, is that I control drag that button to that view and hit "show" to link them. Now say I have another button in that new view I just linked to. Xcode doesn't seem to let me just control drag that button onto the text in viewcontroller.swift, I believe that this is because they are two separate view controllers now however I have not a clue where the second viewcontroller2.swift file may be. Or, maybe, there is an easier way to link the two views together and actually be able to modify the source files?
If you're trying to find a "ViewController2" you won't find it, because you have to create it! Use Command-N to create a new file and choose "Cocoa Touch Class". Name it something like SecondViewController and make sure it's a subclass of UIViewController. Now you can go back to interface builder and change the class of the second view controller to whatever name you just chose, like SecondViewController.
To address the other part of your question (I think), I'm not exactly sure what you're trying to do. If you want some of your data to transfer to the new ViewController, use the prepareForSegue function in the first ViewController.

When using storyboards with Swift, how do I also include code?

I often look up questions about Swift regarding formatting and Views, and answers I find will include lines of code. If I am using storyboards, where should I look to include code?
Thanks in advance.
You include code to it's corresponding class.
let's say you're using a UIViewController in storyboard:
make a class of type ViewController,
and put the class name for it
now both the class and the storyboard viewcontroller work together. and you can just add code in that class...
Adding onto slimboy's answer, if you are beginner, you might forget to connect the IBOutlets/IBActions. Here is how.
You switch to double pane view with the storyboard on the left and the view controller on the right.
Then ctrl click from the view element to the top of the view controller
Name you view whatever (myTitleLabel).
Now you can use code to refer to the myTitleLabel. IBAction works the same, but make sure to change the option to Action (default is outlet in Swift).

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

UzysSlideMenu: how to use several view controllers?

I just came across a slide-in menu I really like: https://github.com/uzysjung/UzysSlideMenu
I would like to use this menu for an application that uses several view controllers (UIViewControllers and UINavigationControllers).
In Xcode, I created a single view application and made the view controller (MenuViewController) show the menu, like the creator did in his example project. I added more view controllers to the storyboard and connected them via segues to the MenuViewController. Upon selecting a menu item, these segues are triggered and the selected view is shown - so far so good.
But now, I run into the following problem:
All my view controllers are shown in full screen. That means that VCs that get segue'd in the viewport don't show the menu, because it's just not implemented there. I could put the menu in every VC, but that doesn't seem to be the right way to do it (even if I use some custom delegate method that every controller calls, like putMenuInViewController:(UIViewController *)target). I think I need something like a global singleton for the menu and make it appear in every view controller, but I have absolutely no idea on how to it or what to google for.
Any points into the right direction are greatly appreciated :)
I think you need to implement one root view controller with this menu as singleton, and add other view controller as child view controller to it.
I wrote a post about it, you can find it here:http://antrix1989.blogspot.com/2013/09/uiviewcontroller-as-singleton.html

iOS: Map and list in one ViewController

I would like to put two different views( list and map) into one View Controller. User will be able to change view by pressing the right button on the top. For both there will be search option. If this possible, I want to separate classes for list and map.
I would be gratefull for some tip how to make it.
views http://img201.imageshack.us/img201/1104/56044506.png
I would suggest you create a parent class that is a subclass of UIViewController, the purpose of this class will be to handle the search bar functionality and any common delegate callbacks from your datasource.
From a theory perspective this class will act as an abstract class, meaning it should only ever be subclassed rather than directly initialised, but as this is not possible to enforce in objective-c don't worry too much about that.
This next part depends on whether you'd like to use two view controllers for list and map (as at the end of the question you said you wanted to use two classes...?)
You can then either create two UIViewControllers, one for map and one for list, and they both will subclass the above mentioned abstract class. This will allow them to inherit the datasource delegate callbacks and search bar functionality.
Or you can combine the two into one UIViewController that subclasses the above mentioned abstract class and as in A'sa Dickens answer, you can manage two views in a single xib file and swap between them by hiding and showing, or adding and removing them from their superview.
Hope this helps.
with in your xib or storyboard have 2 views 1 for the map view and 1 for the list view, when ever they click one of the buttons it hides one of the views and reveals the other with the hidden property
[listView setHidden:NO];
that's an example ....
make sure you have a reference to both views, and that the reference is linked. That is an obscure way to do it. you could also try a tab view controller... but that is more complicated
Use a UITableView and a MKMapView and add them to the same content view.
Use the hidden property to hide and unhide the views depending on the button clicked by the user.

Resources