Custom UIView in Interface Builder - xcode

I am trying to create a custom UIView for an iPhone app. The UIView contains some standards views such as UILabel and UIImageView.
I have created a new nib file and designed the control there. Afterwards I created a new class that extends UIView. I have put owner to the class, linked the controls from the nib to the class, implemented the methods in initWithCoder: etc.
Here is the catch: if in the storyboard I add a UIView object with the my UIView custom class, at build time everything works. But in the Interface Builder I still see a white rectangle.
I had a look on the Apple tutorial here (https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/chapters/CreatingaLiveViewofaCustomObject.html) and it works as stated if I implement drawRect method.
But the controls are not displayed, such as UILabel.
My question is if there is any way to see the custom control in the Interface Builder and how may I achieve this?

Related

Xcode UICollectionViewCell xib not displaying any views added to it

I'm trying to create a custom UICollectionViewCell backed by a *.xib file.
However, when I try to add subviews to the cell, interface builder (as well as an actual instance of the cell inside the app) doesn't show them at all.
It doesn't matter whether I add in an UIView as a contentView or not, all subviews seem to be invisible.
This happens in Xcode 7.2 inside a tvOS project. Does anyone experience the same issue or can see what I'm missing?

cocoa NSPanel initWithCoder not being called from MainMenu.nib

I have a top level NSPanel in my MainMenu.xib. I specified the class
of the panel to be my class which subclasses NSPanel. I was expecting the
method initWithCoder: to be called when the application launched but it
is not.
Does anyone know what I need to do get initWithCoder: called from MainMenu.xib
when the application launches? I'm new to Xcode and the UI of the xib file
in xcode is a bit overwhelming.
Thanks.
According to the documentation:
Although the NSWindow class inherits the NSCoding protocol from
NSResponder, the class does not support coding.
Have you checked the other initializers?
-initWithContentRect:styleMask:backing:defer:
-initWithContentRect:styleMask:backing:defer:screen:

Using XCode storyboard to instantiate view controller that uses XIB for its design

I have a UIViewController subclass that I created previously that had its controls laid out in a XIB file.
I'd like to use this view controller in a storyboard now, but it seems although I can indicate a view controller's classname in the storyboard, I can't tell it to load the XIB.
I'd rather not move everything from the XIB to the storyboard but keep it in its separate XIB.
How can I get this UIViewController in the storyboard to load my XIB?
Delete the View contained by the view controller in the storyboard.
Then provide the view by configuring a nib file with the same name
as the view controller class. For example if the view controller
class is called MyViewController, name your xib file
MyViewController.xib.
EDIT Note that Swift seed 5 started breaking this technique, because it mangles the name of the .xib file it's looking for. See my answer here for workarounds: https://stackoverflow.com/a/25539016/341994 Basically this name matching was broken in iOS 8, but then Apple repented and fixed it so that it works again in iOS 9.

Xcode 4 / Interface Builder "master" view UITabBarController template

I started an iPhone App with the Xcode template for UITabBarController, which created a couple of default UIViews (MainWindow, FirstView and SecondView).
The MainWindow xib shows the tabbar itself, which can be configured there.
FirstView and SecondView have an unselectable UITabBar anchored to the bottom, which is ostensibly to show the relationship to MainWindow.
Note that I've created many new views that are part of the main UITabBar and they work fine, but they don't show that UITabBar at the bottom in Interface Builder.
My question is, how does that work, and how can I create a new view such that it will show that unselectable UITabBar at the bottom?
What you're seeing is simply Interface Builder's "simulated metrics" and it shouldn't actually have any bearing on the app's behavior. But this is how you can change it:

How to use NSWindowController?

I'm looking in to using NSWindowController and I just can't think how to get it working. How do I start using it?
It's difficult to answer this question without knowing what you're trying to do. However, if you are writing a document-based application, an NSWindowController is automatically created for each window you create, so you don't need to create one specially.
The way I use NSWindowController is I create a different subclass for each type of window in my application. For example, I might have a 3D application with an AppWireframeWindowController and an AppPreviewWindowController. Each subclass automatically loads the correct nib file, and has code that hooks the document's data to the views in the nib.
If you are using storyboards you can connect an NSWindowController subclass up in IB. Otherwise if you are using nibs and have just the default template for a Mac Cocoa app then you may need to make it in code or just use a subclass of NSWindow.
Otherwise you can create a new NSWindowController and check the 'Also create XIB file for user interface' and it will give you the nib and also the NSWindowController subclass. It is basically a new nib where 'File's Owner' is your NSWindowController and the Window is the .window object inside the NSWindowController and the delegate is also pointed there.
You may be able to modify that.

Resources