Xcode Create .xib File For Already Created Files - xcode

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.

Related

Xib file: Can't drag a View from a xib file to a swift file

I just dragged and dropped a View to a xib file. I added some constrains and tried to Ctrl drag from the View to a .swift file with the assistant editor, but it bounce back, what am I missing?
I was setting the View's custom class instead of the File's Owner. Once I set the File's Owner to the custom class, I was able to control-drag from the view in the storyboard over to my class. Hope this helps someone.
The xib file needs to be a subclass of the file you are trying to ctrl+drag to.

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 :)

Handling **** OSType in a Cocoa NSDocument application

I have written an editor that I would like to be able to handle any file, including those with no extension.
I think that I need to add **** to the Document OS Types in my filetype entry in the Info.plist, but whereas this does allow me to drag any file to the dock icon, it doesn't attempt to open the file with the associated NSDocument class, instead telling me that my application doesn't know how to open the "SimpleText Format" format.
Any help with the step I have missed here would be greatly appreciated.
You need to implement a custom NSDocumentController subclass and override the typeForContentsOfURL:error: method, returning the name of a document type, specified by CFBundleTypeName in the application’s Info.plist file
In order to make the application use your custom NSDocumentController, just drag a generic object into your MainMenu.xib file and assign it your document controller's class. The document architecture will then automatically use your document controller subclass instead of a generic NSDocumentController.
Solved this eventually by creating a second document type linked to the same nsdocument subclass with * in the extensions box.

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

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)?

How to create new window/form in MonoTouch/MonoDevelop/Interface Builder. (Mac)

I have created my first application in MonoDevelop. I'm having difficulty to create a second window (form).
If I create a new UIView it has .cs and .designer.cs files attached to it. It looks good, but it doesn't have appdelegate to attach events to.
If I use the new UIWindow I don't have .cs and .designer.cs files attached to it. And I don't have delegates either.
If I copy the original MainWindow and rename it, it almost works, I have delegate and .designer.cs but it complains about duplicating certain objects. Like "Window", "AppDelegate"
So how am I supposed to create some new forms that needs some buttons and events to deal with?
In an iPhone app, you should generally only have 1 window.
Create a new UIViewController with your desired elements, and present it as a "modal" view controller over your other controllers. It will function similar to ShowDialog(), except it won't be a blocking call.
The methods are PresentModalViewController() and DismissModalViewControllerAnimated().
Here is a decent example.

Resources