我已经将UIViewController类子类化,如下面的代码所示。 下面编码的视图控制器由Storyboard在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
我错了什么?
谢谢!
答案 0 :(得分: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。打开Xcode 4.3 UIViewController模板 当你取消选中“使用XIB for User Interface”时,苹果的一些聪明人认为你想在代码中创建你的视图。他可能完全错过了故事板宣布。
删除该部分后,请考虑在http://bugreport.apple.com/
提交错误编辑:Xcode 4.3.2修复了这个错误。该模板不再包含- (void)loadView