1

次のコードに示すように、UIViewControllerクラスをサブクラス化しました。以下にコード化されているビューコントローラーは、ストーリーボードによってTabBarControllerでインスタンス化されますが、そのビュー(ラベル、ツールバー、Interface Builderを使用して追加したもの)は表示されません。表示されるアイテムは、TabBarControllersタブバーのみです。

.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

私は何を間違えましたか?

ありがとうございました!

4

1 に答える 1

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

それはあなたのせいではありません、Appleのせいです。Xcode4.3UIViewControllerテンプレートが完成しました。
アップルの賢い人の中には、「ユーザーインターフェイスにXIBを使用する」のチェックを外すと、コードでビューを作成したいと考えた人もいます。彼はおそらくストーリーボードの発表を完全に見逃していました。

その部分を削除したら、http://bugreport.apple.com/でバグを報告することを検討してください。

編集:このバグはXcode4.3.2で修正されています。テンプレートにはもう含まれていません- (void)loadView

于 2012-02-20T20:34:32.880 に答える