How do I see what viewController a class is attached to? - xcode

It's easy to tell what class a viewController uses, but what about the other way around: if you have a class and wants to see what viewController it's attached to. Is there a way to do that? I'm now in a peculiar position where I have made changes in a class but don't know how to test the changes because I don't know which viewController to enter in the simulator to see the result.

Follow the screenshot then you will get the name of your viewcontroller class.
select Main Storyboard
select your ViewController
select identity inspector
you will see the class name

Related

Xcode, Custom Class meaning

I searched all around stackoverflow and other websites but can not find a very simple thing. I suppose, it could have been answered already, then, could anyone just link the answer?
I am interested in what "custom class" in Xcode is in attributes inspector and how it works, what it actually does. I know very well how to make things work, but I do not have understanding of what I am doing.
To clarify. We can create a UITableViewCell class with, say, name cellClass, then we create .xib with the same name. Inside of .xib we drag UITableViewCell on the canvas and select its custom class - the name of the UITableViewCell class created before - in attributes inspector. So, what is this custom class in the attributes inspector is not clear for me. The example is very specific though, since we are using custom class for other things.
Thanks.
I think you are talking about the possibility to change the class of a predefined object in a .xib. If you insert a button to the interface, its class is NSButton, this to say that you instanciate an NSButton. But, you may have the need to extends NSButton into a MyButton class with specific added properties, methods, etc. If you want to instantiate it through .xib then you just have to drag'n'drop an NSButton and change its class to MyButton in the Identity inspector tab, Custom class form.
It is not very frequent to use NSButton this way, but much more common for some other objects, NSView for example (read Apple docs on subclassing NSView)
Are you talking about (Extensions, categories).
Please refer to this link:
Extensions
If you having issues in creating new subclases in xcode 7.1 then please click on:
File->New->Cocoa Touch Class-> Classname and select subclass of, it will works and you will be able to assign classes to uiviewcontrollers as well.

App Crashing trying to reach storyboard

I'm getting an error connecting to my storyboard. I have a navigation controller connected to my view controller as a root. Everytime I play the application, it crashes. I get this error:
Unknown class ViewController in Interface Builder file.
(lldb)
scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier-
What's this even mean?
My view controller is defined right under the normal code.
import UIKit
class ViewController: UIViewController {
//some code here
It sounds like one of the scenes in your Storyboard is (a) referencing a class, AboutMeViewController, which you haven't defined.
It further sounds like this scene also doesn't have any segues pointing to it, nor does it have a unique identifier. Thus there's no way to load it.
Select each scene in your storyboard in turn, select the outermost view controller object, and use the identity inspector to see the class of that view controller.
Since I transferred the storyboard from another project, it was linked to another project. I refreshed the "Custom Class"/"File Owner". Usually it's hidden and it confuses people but it's there. To locate it find the newspaper looking like icon and press on it. It'll be the first option all the way at the top.

Control-drag to AppDelegate only

Xcode 6.1, OSX not ios, allows me to Control-drag from a button in MainMenu.xib to AppDelegate only. This is unfortunate for me because my IBAction must include view methods like [self setNeedsDisplay:YES] . I need to Control-drag it into my MyView file, which will tolerate them. This also makes more sense.
Control-dragging from the button to any file other than AppDelegate does nothing.
Identity Inspector > Class is set to MYView.
How can I make this work, and how does the fix work?
Also, why is it now restricted to AppDelegate? Perhaps a timing issue?
Thanks ahead,
Nick
Try dragging an empty object from the object library to the area where you see 'AppDelegate' then selecting it and setting its' class to 'MyView' then secondary dragging to that object to create the IBAction.

Swift class to interact with Interface Builder via IBOutlet

Good evening all,
I'm slowly working through my first OS X app. I have been having a hard time getting my Swift class to interact with an NSPopUpButton. Just to make sure I was doing it right, I created a new project and successfully erased all entries and entered text into the NSPopUpButton via AppDelegate. However, as soon as I try to move the same functionality to my own class, I can't even get the IBOutlet connection across to the new class.
Is a particular subclass type required of a new class to work properly with interface builder?
Here is a screenshot of the class I have created, as well as AppDelegate where I am trying to call the function belonging to this class.
Finally, here is the IB element in question, should I be able to select my own class under the 'Custom Class' inspector?
I am an iOS developer, but I would imagine the same principles would apply to your situation.
A ViewController class and an interface created in interface builder are two seperate things. While it may appear that they are connected via an iboutlet, they are actually independent and one can be instantiated without the other.
Currently, you are only creating an instance of your ViewController class in your App Delegate - and that's all. The system has no idea that your xib even exists! The outlets will only be connected once your app connects your xib to your ViewController class.
How do we do this? It's actually quite simple. Instead of instantiating our view controller like this:
let viewcontroller = ViewController()
We would connect our view controller to our xib in the instantiation:
let viewcontroller = ViewController(nibName: "MainWindow", bundle: NSBundle().mainBundle)
The nibName is telling the system the file name of your xib, and the NSBundle().mainBundle is telling the system where to look for the xib.
This will all only work if your xib has been assigned a custom class, like you mentioned. In your xib in interface builder, select the entire view controller. Then, in the custom class inspector type in the name of your ViewController class (in your case: ViewController - it should autocomplete). This will make sure your outlets are connected.
And you should be set up!! Let me know if you have any more problems come up.
Good luck!
EDIT:
This replaces the first part of my answer, however the part about hooking things up in Storyboard remains true. Upon reconsidering, I've believe I've realized that we are only creating the view controller, and not adding it to our view. Despite this, I believe we can take a short cut solution by adding one method to your view controller subclass (the one we set in the Storyboard). Start typing in viewDidLoad, and it should autocomplete. Type in super.viewDidLoad() at the beginning of the method. After that, type self.listUpdate(). This should work if the classes are hooked up correctly in Storyboard. This means you can delete the variables you created in the App Delegate.
Reference: You might also find Apple's documentation on creating a view controller handy (it's in Objective C online, but can be easily converted to Swift - it's the concept that counts): NSViewController Class Reference

Can't ctrl+drag into ViewController.h from second Viewcontroller

I am building an iOS app for fun and here is where I run into trouble. I can insert an outlet and action in the ViewController.h files directly from my first View Controller through the ctrl+drag method; however, when I try ctrl+drag on the second ViewController it will not allow me.
Ctrl+drag on first ViewController
Ctrl+drag on second ViewController
You have the wrong document open in the assistant editor. It should be ViewController.h, but you are displaying UIViewController.h.
Check you have correctly set your second view controller to your custom class ViewController using the Identity Inspector (third of the right hand utility panels) then make sure it's header file is the document you are displaying on the right.
update
From your comments, you are having difficulty setting the second view controller to a custom class.
Here is how you select it in the storyboard. Note that you are selecting the View Controller, not it's topmost View
Copy and paste the class in the field "Class." You then need to press ENTER to take effect. Example

Resources