2012-02-20 69 views
1

我已經子類UIViewController類,如下面的代碼所示。 以下編碼的視圖控制器由TabBarController中的Storyboard實例化,但其視圖(標籤,工具欄,我已使用Interface Builder添加)未顯示。顯示的唯一項目是TabBarControllers選項卡欄。子類UIViewController未顯示

.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 

我是怎麼了?

謝謝!

回答

1

閱讀本方法的註釋,然後徹底清除方法:

- (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. 
} 

你根本就沒有一個視圖(即self.view),因爲你沒有創建一個,所以你的viewController節目空了。當你想在代碼中創建你的視圖時,你會使用- loadView。但你使用故事板來創建你的視圖,所以你不能使用- loadView

這不是你的錯,責備蘋果。 Xcode 4.3 UIViewController模板已打開。
蘋果的一些聰明人認爲,當您取消選中「使用XIB用戶界面」時,您希望在代碼中創建視圖。他可能完全錯過了故事板公告。

你已經刪除後的那部分想在http://bugreport.apple.com/

編輯配方中的錯誤:此錯誤是固定在Xcode 4.3.2。該模板不再包含- (void)loadView

+0

謝謝,Matthias。你的回答幫了我很多! – AlexR 2012-02-20 21:14:37