iosobjective-cuiviewcontrollertabbarcontrollerloadview

setBackgroundColor crashing when loadView implemented for ViewController used for UITabBarController


I have a view controller which is used in appDelegate.m as part of a tabBarController (code snipped below)

 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];

The code inside feedViewController is posted below ,the app crash is solved when I removed the loadView from the below implementation

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

Please help me to understand why this is happening.


Solution

  • call super method in the load view

    -(void)loadView { [super loadView]; }
    

    hope this will help you, good luck