Question

I've noticed that there is no option to choose "With XIB for user interface" in Xcode 4.3 when you create a new file.

What i do is, i created a new file with h and m and after that i add a new View file with xib extension but he not recognized the header file.

Where is the old option to create a 3 files in Xcode 4.3 (h, m and xib) ? is exist there?

Thanks.

Was it helpful?

Solution

Works for me for both iOS and OS X projects.

Under iOS you must use UIViewController* as the super class. That is in the field labeled "Subclass of" input UIViewController. And the same goes for OS X but there "Subclass of" should be NSViewController**.

*: UITableViewController and similar view controllers in UIKit should also work.

**: NSTableViewController and similar view controllers in Cocoa should also work.

OTHER TIPS

To get your view loaded from xib do the following:

  1. Create h+m file for it (Command+N -> [Cocoa Touch|Cocoa] -> Objective-C class)
  2. Create xib file (Command+N -> User Interface -> View)
  3. Open xib in Interface Builder, select only one view exist there and insert your class name in Custom Class field (located in right sidebar, 3rd tab)

After loading view from xib you will get the view you wanted

+ (id) instanceWithXib: (NSString*) nibName
{
NSArray* elements = [[NSBundle mainBundle] loadNibNamed: nibName owner: self options: nil];
for (NSObject* object in elements) 
{
    if ([object isKindOfClass: self.class]) 
        return object;
}

return nil;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top