为用于 UITabBarController 的 ViewController 实现 loadView 时 setBackgroundColor 崩溃
setBackgroundColor crashing when loadView implemented for ViewController used for UITabBarController
我有一个视图控制器,它在 appDelegate.m 中用作 tabBarController (下面的代码片段)
self.window=[[UIWindow alloc ]initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *baseTab=[[UITabBarController alloc] init];
self.feedViewController=[[FeedViewController alloc] init];
self.favViewController=[[FavViewController alloc] init];
[baseTab.tabBar setTintColor:[UIColor yellowColor] ];
[baseTab setViewControllers:@[self.feedViewController,self.favViewController]animated:YES];
feedViewController 中的代码贴在下面,当我删除 loadView[= 时,应用 crash 已解决 24=] 来自下面的实现
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
[self setTitle:@"Feed"];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor blueColor]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loadView
{
}
请帮助我理解为什么会这样。
在加载视图中调用超级方法
-(void)loadView { [super loadView]; }
希望对你有所帮助,祝你好运
我有一个视图控制器,它在 appDelegate.m 中用作 tabBarController (下面的代码片段)
self.window=[[UIWindow alloc ]initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *baseTab=[[UITabBarController alloc] init];
self.feedViewController=[[FeedViewController alloc] init];
self.favViewController=[[FavViewController alloc] init];
[baseTab.tabBar setTintColor:[UIColor yellowColor] ];
[baseTab setViewControllers:@[self.feedViewController,self.favViewController]animated:YES];
feedViewController 中的代码贴在下面,当我删除 loadView[= 时,应用 crash 已解决 24=] 来自下面的实现
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
[self setTitle:@"Feed"];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor blueColor]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loadView
{
}
请帮助我理解为什么会这样。
在加载视图中调用超级方法
-(void)loadView { [super loadView]; }
希望对你有所帮助,祝你好运