Question

I have subclassed the UIViewController class as shown in the following code. The view controller coded below is instantiated by Storyboard in a TabBarController, but its views (labels, toolbars, which I have added using Interface Builder) are not shown. The only item shown is the TabBarControllers tab bar.

.h:

@interface FinstatViewController : UIViewController <SplitViewBarButtonItemPresenter,UISplitViewControllerDelegate>
@property (nonatomic, strong) UIBarButtonItem *splitViewBarButtonItem;
@property (weak, nonatomic) IBOutlet UINavigationBar *toolbar;
@end

.m:

#import "FinstatViewController.h"

@interface FinstatViewController ()

@end

@implementation FinstatViewController
@synthesize splitViewBarButtonItem = _splitViewBarButtonItem;   // implementation of SplitViewBarButtonItemPresenter protocol

@synthesize toolbar = _toolbar;                                 // to put splitViewBarButtonItem in

- (void)setSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
    if (splitViewBarButtonItem != _splitViewBarButtonItem) {
        NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
        if (_splitViewBarButtonItem) [toolbarItems removeObject:_splitViewBarButtonItem];
        if (splitViewBarButtonItem) [toolbarItems insertObject:splitViewBarButtonItem atIndex:0];
        self.toolbar.items = toolbarItems;
        _splitViewBarButtonItem = splitViewBarButtonItem;
    }
}

- (void)awakeFromNib  // always try to be the split view's delegate
{
    [super awakeFromNib];
    self.splitViewController.delegate = self;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)loadView
{
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //self.splitViewController.delegate=self;
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setToolbar:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES; // (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

What did I wrong?

Thank you!

Was it helpful?

Solution

Read the comment of this method and then remove the method completely:

- (void)loadView
{
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
}

You simply don't have a view (i.e. self.view) because you don't create one, so your viewController shows up empty. You would use - loadView when you want to create your view in code. But you use storyboards to create your view, so you MUST NOT use - loadView

It's not your fault, blame Apple. The Xcode 4.3 UIViewController template is f'd up.
Some smart guy at apple thought that you want to create your view in code when you uncheck "With XIB for User Interface". He probably missed the storyboards announcement altogether.

After you have removed that part think about filing a bug at http://bugreport.apple.com/

EDIT: This bug is fixed in Xcode 4.3.2. The template does no longer contain - (void)loadView

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top