How can i make a .XIB from .h and .m files? - xcode

I'm working on an existing project which I basically need to create a .XIB
so I can then put in UIToolbar and UIButtons ect.
On the App already it has a Tab bar but has been inputted through code and not the Interface Builder.
I would appreciate any guidance on my problem.
Kind Regards.

There is no automatic code that does this for you. You'll need to look in the code, find all UIView instances that need to go into the nib and manually create it. Then you'll have to be sure to set the frame of each of them to the same positioning as what is defined in the code. Finally, you'll have to be sure to remove all of that from the code (once it is fully migrated to the nib). Finally, you'll have to be sure that the components are referenced only after the nib has fully loaded (which might not have been the case in the current code).
Why not keep the components in the code (and just use nibs for new views)?

Related

How to change Xcode generated files to Swift from Objective-C

I am new to Xcode and am not sure what I am doing. However a projected I am working on started with Objective-C, and upon realizing aspects of the language, I'd like to change to Swift. Whenever I make a view controller on storyboard, it makes it in Objective-C. How can I change the settings so it makes the auto-generated files in Swift instead?
Should be easy, right? I do not want to restart the project.
Thanks.
Whenever I make a view controller on storyboard, it makes it in Objective-C
A view controller on the storyboard has no language, and making a view controller in the storyboard does not auto-generate any files, so the question as it stands makes no sense.
What does have a language are the view controller subclass files you create for the project. The language of those is up to you at the moment of creation. Note the language pop-up in the File > New > File dialog:

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.

Xcode Create .xib File For Already Created Files

I have a few files (.h and .m) that do not have a corresponding .xib or storyboard file connected to them. I know how to create a new .xib file but how would I create one and have it connect to the other files that correspond to it? Thank you so much!
Simply creating it and including it in the target will suffice.
The default implementation of loadView will look for a NIB/XIB with the same name as the class (take a look at the UIViewController documentation for more information on that process.)
If your class has bindings, just name them correctly and add IBOutlet before them in the header file to make them visible in IB.
If you have overridden your initializer, you may need to incorporate some calls to super. The easiest way to see exactly what would be to create another view controller and add a XIB at the same time using Xcode's interface, and take a look at what is created. This isn't likely, though, as most calls to super end up going through the right path in the long run.
Post specifics if you have difficulty.
First add new file as user interface and select view. Then give name whatever you want. then in that xib file's "File's Owner" set the class for what you want xib file.
then bind the view with "File's owner"'s view. That shit.. Now you can access that class by initWithNibName method and in that method give nib name of that newly created xib file. may be it works for you.

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't find the .m file for UITableViewController

I realize this is likely an inane question, but here goes:
I'd like to set the background of a uitableview by code (created using storyboard), however... the only .h file I can find is in the uitableviewcontroller.h in the frameworks folder. There's no .m file anywhere that I can see, and I need to place code in the "viewdidload" for that particular table.
Thanks for any help in advance!
You need to create your own class that extends UITableViewController. There you can override viewDidLoad and put your code there. Then, in your storyboard, set the custom class for your table view controller to the class you created. You do that in the 3rd tab inside the right-side pane.
Even if the source code for UITableViewController were available (and it is not, since Cocoa is a closed-source framework), your changes there would apply everywhere that class is used, which is never a great idea :)

Resources