How to find the editor for multi view controllers - xcode

I am very new to xcode, got stuck in finding the editor to modify the code when created multiple view controllers. Whenever I click on any of the view controllers, I only see same editor contents and cant move to the others for coding.
I searched the web and stackoverflow but could not find a clear guideline on how to manage the editors for multiple view contollers. I have attached a snapshot.

You don’t “find” code. You create it.
When you drag a view controller into the storyboard, it has the default class of UIViewController. It is up to you to make a new code file where you subclass UIViewController, and then to go back to your storyboard and change the view controller to that subclass in the Identity inspector.

Related

Unable to see custom classes in Interface Builder drop down

I'm using Xcode 6.1.1, and cannot select my custom class from the drop down. Because of this, I believe it is causing several other related issues (see below).
Symptoms:
When using the IB drop down to choose a custom class, none of the custom classes appear.
IB_DESIGNABLE and IBInspectable do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined as IB_DESIGNABLE.
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
Suspected to be related: WatchKit: unable to find interface controller class
How can I fix this?
Things that worked:
Try on another machine. (This leads me to believe the machine has some setting that is messing this up.)
Reinstall Xcode.
Moving the project to a new location (in this case a git repository), fixed it once.
Things I tried that didn't work (but have worked for others):
Restart Xcode
Restart machine (this worked once before, not this time)
Create a new storyboard.
Create a new subclass (not just rename it).
Create a new project via Apple's single view template.
Cleaning the project
Deleting derived data
Reindex the project
Remove localization on the storyboard file.
Things I tried that didn't work:
Naming the subclass according to Apple's conventions (e.g. instead of View use ABCTestView).
Import the .h of the class in the .h and .m of the view controller.
Try on another version of Xcode, which is already installed (beta 6.2).
Related discussions:
https://discussions.apple.com/thread/3054574?start=15&tstart=0
Storyboard uiviewcontroller, 'custom class' not showing in drop down
This wasn't your specific situation but I was in a similar "rip my hair out" moment. When creating custom controller classes and using the interface builder, you must make sure to click the yellow button at the top of the view you're working with (the view controller button). Otherwise the custom ViewController class won't show up in the custom class drop down menu within the identity inspector.
One thing that worked for me after inexplicably seeing the issue where the "Designables" row would not appear in the Custom Class section of the Identity Inspector:
Before (not functioning: Designables did not appear and Interface Builder did not render my class):
IB_DESIGNABLE
#class MyCustomClass;
#interface MyCustomView : UIView
After (functioning: Designables did appear and Interface Builder did render my class):
#class MyCustomClass;
IB_DESIGNABLE #interface MyCustomView : UIView
So it appears that Xcode is very sensitive to the order of things.
This is what worked for me:
I somehow lost the view reference, so all i did was to drag from a little circle "New Referencing Outlet" to the main view of the .xib, and BOOM!
Here are some possible solutions:
When using the IB drop down to choose a custom class, none of the custom classes appear.
Manually type the name of your custom class instead of trying to find it in the dropdown. Sometimes IB will autocomplete the name of the class as you type, especially if you follow Apple's conventions, i.e. YourView as a subclass of NSView.
IB_DESIGNABLE and IBInspectable do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined as IB_DESIGNABLE.
If the view does not begin as a Custom View either dragged from the Object library or created from Editor > Embed In > ..., for some reason changing the Custom Class in the Identity inspector doesn't make a difference. To fix this, right-click the .xib and choose Open As > Source Code. Search for the view you want to fix (giving your view a label that is easily identifiable in IB will make this easier). You will find an entry like this:
<view ... customClass="YourView">
...
</view>
Change view to customView so that the entry resembles:
<customView ... customClass="YourView">
...
</customView>
then right-click the .xib again and choose Open As > Interface Builder XIB Document and you should now see a Designables entry under Custom Class in the Identity inspector of IB and Debug Selected Views will be available under the Editor menu.
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
Doesn't sound like your exact problem, but on a dual-monitor/multi-monitor setup, if IB is on a different monitor from the source code window, go to Apple menu > System Preferences... > Mission Control and uncheck Displays have separate Spaces. This may have some visual side-effects (like window drop-shadows bleeding into other monitors) but it will fix the problem of ctrl-dragging onto a separate monitor.

Add a second UIViewController within a single-view application

I have a single-view application open. I need to have two storyboard views (UIViewControllers), because one is a Table View, but when one of the Table View elements is selected it brings up another screen with a normal UIViewController. Is there any way of creating a second storyboard view (UIViewController)?
Of course! Those templates Xcode provides are in no way "set-in-stone". When Xcode created your Single-View Template, it just gave you a base for creating something more. You can create additional classes, view controllers, views, and resources (other than what Xcode starts you off with in a few ways).
To add another View Controller to your Storyboard, just drag and drop one from the Object Library:
It seems like you do not have a basic understanding of using or developing with Xcode. I would recommend reading over all of Apple's documentation on Xcode before going any further. The Building A User Interface section may be of particular interest to you.

Connecting code to UI in storyboard with multiple ViewControllers, Xcode

I have a storyboard project in Xcode. I have added an additional ViewController and dropped in a button, text box, etc. I can get from the initial to the secondary View Controller, but I cannot seem to be able to connect the button to the code. I've tried adding additional classes with XIBs and even from a blank adding in the XIBs. How do I connect the code I have written for a button to do work on the second View Controller?
If you have the button created on the storyboard. You have to make an
-(IBAction)clickButton...
in the .h and .m code files. You can easily connect the code to the button by dragging the line from the dot (in front of the code name) to the button.
If you have created the Button fully in code. You have to specify which code to be executed on click.
[self.buttonName addTarget:self action:#selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
Here's the answer. You add new files to your project, and just for giggles, we'll call them NewViewController of the UIViewController class. Then, highlight the second view controller in the storyboard, choose identity inspector, and under Custom Class (at the top) you change the class to the name of the recently added NewViewController class. Now, all your code will connect to objects and so on. Thanks again for the help all and now I can rest in peace lol.

Cocoa how to handle multiple views?

I'm have done some development on iOS using Storyboards. Now I'm building on app for Mac OS X and it seems that an equivalent for Storyboards does not exists.
For instance, I'm need to build some kind of wizard, which contains four different windows or views (step 1 to 4).
Currently I've created one Window xib (the standard MainMenu.xib), containing a window with the first view, and three other custom views. Using this approach, I can create outlets and actions, making me able to change the contentView of my window, e.g. when clicking an button. This seems as a fair solution, and my views are all grouped cleanly inside a single xib. But this also cause that the logic for all the view should be handled by the same File's Owner, right? For instance saving the settings on each step and controlling the interaction between the different views.
How is the preferred way to handle a situation like this? Should I instead create four different windows, and maybe in four different xib-files? If you know an sample project somewhere from the internet showing how to handle multiple windows, please give me a hint.
You can make use of the NSViewController class for this purpose. Each view controller will be responsible of loading a xib associated with it and all logic associated with the views can go inside the controllers (Same as in iOS). The MainMenu.xib can now load appropriate views after initialising the required view controllers.
Here is a sample app for your reference.
https://developer.apple.com/library/mac/samplecode/ViewController/Introduction/Intro.html
In xcode, go to File->New->New File
Add an objective C class and set it to subclass of "NSViewController".
This will itself create yourController.h, yourController.m and yourController.xib.
Now you can keep your view and its controller class seperate.

can ttnavigator render a xib view in objective c?

I have followed the three20 ttnavigator example in order to make my own app, but I have seen than the view is created in controller, but I would like to make my view in a xib file and then render it from controller when openURLAction is fired, how is it posible?, thanks
I used to overwrite the initWithNibName to make my view in a xib file, navigator openURLAction is ok.

Resources