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

あなたは単にあなたが1を作成しないため(すなわちself.view)ビューを持っているので、あなたのViewControllerを示していません空になる。コードでビューを作成する場合は、- loadViewを使用します。しかし、ストーリーボードを使用してビューを作成するので、使用しないでください。- loadView

アップルが責任を負うわけではありません。 Xcode 4.3 UIViewControllerテンプレートが起動します。
リンゴのスマート・ガールは、「With With XIB with User Interface」のチェックを外すとコード内でビューを作成したいと思っていました。彼はおそらくストーリーボードの発表を全く忘れていたでしょう。あなたは一部がhttp://bugreport.apple.com/

EDITでバグを提出について考えることを削除した後

:このバグは、Xcodeの4.3.2で修正されています。テンプレートには含まれていません- (void)loadView

+0

ありがとう、マティアス。あなたの答えは私を助けました! – AlexR

関連する問題