Cannot set root view controller - ios

I keep getting the warning
Application windows are expected to have a root view controller at the end of application launch
Ive been looking for a fix but all the solutions I found matched my code.
Thanks in advance its probably something simple but i've been stuck on it for awhile now.
AppDelegate.m
self.rootController = [[UITabBarController alloc] init];
DownloadTableView *view2 = [[DownloadTableView alloc] init];
view2 = [[UIStoryboard storyboardWithName:#"DownloadTableView" bundle:nil] instantiateViewControllerWithIdentifier:#"Download"];
TableViewController *view3 = [[TableViewController alloc] init];
view3 = [[UIStoryboard storyboardWithName:#"TableViewController" bundle:nil] instantiateViewControllerWithIdentifier:#"table"];
appWebView = [[WebViewController alloc] init];
view3.tabBarItem.title = #"Documents";
appWebView.title = #"Browser";
view2.title = #"Downloads";
self.rootController.viewControllers = [NSArray arrayWithObjects:appWebView, view2, view3, nil];
self.window.rootViewController = _rootController;
appWebView.tabBarItem.image = [UIImage imageNamed:#"Browser.png"];
view2.tabBarItem.image = [UIImage imageNamed:#"Download.png"];
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// [_window addSubview:_rootController.view];
[_window makeKeyAndVisible];

Few lines seems to be redundant which might cause issue, pointed o -
self.rootController = [[UITabBarController alloc] init];
DownloadTableView *view2 = [[DownloadTableView alloc] init];
view2 = [[UIStoryboard storyboardWithName:#"DownloadTableView" bundle:nil] instantiateViewControllerWithIdentifier:#"Download"];
TableViewController *view3 = [[TableViewController alloc] init];
view3 = [[UIStoryboard storyboardWithName:#"TableViewController" bundle:nil] instantiateViewControllerWithIdentifier:#"table"];
view3.tabBarItem.title = #"Documents";
appWebView = [[WebViewController alloc] init];
appWebView.title = #"Browser";
appWebView.tabBarItem.title = #"Browser";
view2.title = #"Downloads";
self.rootController.viewControllers = [NSArray arrayWithObjects:appWebView, view2, view3, nil];
self.window.rootViewController = self.rootController; <-----
appWebView.tabBarItem.image = [UIImage imageNamed:#"Browser.png"];
view2.tabBarItem.image = [UIImage imageNamed:#"Download.png"];
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[_window addSubview:_rootController.view]; <-------
[_window makeKeyAndVisible];

Is all this code called in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method? Is _window field connected to window property?
P.S. There are a lot of useless and weird lines, as well.

Figured it out this morning when I woke up
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Was unnecessary and was conflicting with the tab bar

Related

MMDrawerController configure left menu

My Left menu displace center view. It looks worse than if Left Menu cover center view.
explanation
How i can configure it?
//MMDrawerController
ViewController * centerViewController = [[ViewController alloc] init];
UINavigationController *centerNavigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
ViewController *leftViewController = [[ViewController alloc] init];
UINavigationController *leftNavigationController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
_drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNavigationController leftDrawerViewController:leftNavigationController];
[leftNavigationController setNavigationBarHidden:YES];
[centerNavigationController setNavigationBarHidden:YES];
[_drawerController setMaximumLeftDrawerWidth:300.0];
[_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIColor * tintColor = [UIColor colorWithRed:29.0/255.0
green:173.0/255.0
blue:234.0/255.0
alpha:1.0];
[self.window setTintColor:tintColor];
[self.window setRootViewController:_drawerController];
[self.window makeKeyAndVisible];

App Delegate call for Apple Push Notification doesn't present viewcontroller

I have embedded apple push notifications to my app. When a notification is popped, I get an alert view and when clicked on view, I navigate to a Details controller. But, after clicking on the view button, it does not do anything and it freezes the application. Here's my code to open details in alert view click:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
RearTableViewController *rearView = [[RearTableViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
[self.window makeKeyAndVisible];
Thanks in advance!
//Don't realloc self.window.
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
//Alloc this VC with nib name like initWithNibNamed:bundle:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:#"RearTableViewController" bundle:nil];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
if(self.window.rootViewController){
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
}
else{
self.window.rootViewController = mainRevealController;
}
[self.window makeKeyAndVisible];
Hope it will work.
Remove the following code.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
No need to allocate the window once again. If you do so, you have to set the rootViewController again.

Programmatically create tabBarController in appdelegate

I've been following lot's of different tutorials on how to add a UITabBarController programmatically. This would be easy to achieve using storyboard, but since I'm trying to learn how to do things programmatically I can't do that.
At the moment I've got this code in the didFinishLaunchingWithOptions.
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *tabs = [[NSMutableArray alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[MenuViewController alloc] init]];
[tabBarController setViewControllers:tabs];
[tabs addObject:navController];
[self.window addSubview:tabBarController.view];
Edited code:
tabBarController = [[UITabBarController alloc] init];
MenuViewController *firstTab = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstTab];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navController];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
This does not do anything to my rootViewController called MenuViewController. How can I achieve this?
Thie bellow code for 5 tab UITabbarcontroller try with this bellow code:-
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:#"anasayfaViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:#"SehirRehberiViewController" bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:sehirRehberi];
duyuruViewController *duyuru = [[duyuruViewController alloc] initWithNibName:#"duyuruViewController" bundle:nil];
UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:duyuru];
sikayetViewController *sikayet = [[sikayetViewController alloc] initWithNibName:#"sikayetViewController" bundle:nil];
UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:sikayet];
digerViewController *diger = [[digerViewController alloc] initWithNibName:#"digerViewController" bundle:nil];
UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:diger];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navigationController1,navigationController2,navigationController3,navigationController4,navigationController5];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
You should add tab bar controller as a root view controller:
[self.window setRootViewController:tabBarController];
also it's a good idea to first add object to array and after that do something with it, (other way round):
[tabs addObject:navController];
[tabBarController setViewControllers:tabs];
UIViewController *viewController_favorites = [[[FavoritesViewController alloc] initWithNibName:#"FavoritesViewController" bundle:nil] autorelease];
UIViewController *viewController_project = [[[ProjectViewController alloc] initWithNibName:#"ProjectViewController" bundle:nil] autorelease];
UIViewController *viewController_search = [[[Search alloc] initWithNibName:#"Search" bundle:nil] autorelease];
UIViewController *viewController_setting = [[[SettingViewController alloc] initWithNibName:#"SettingViewController" bundle:nil] autorelease];
UINavigationController *navController_favorite = [[[UINavigationController alloc] initWithRootViewController:viewController_favorites] autorelease];
UINavigationController *navController_project = [[[UINavigationController alloc] initWithRootViewController:viewController_project] autorelease];
UINavigationController *navController_search = [[[UINavigationController alloc] initWithRootViewController:viewController_search] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController_favorite,navController_project,navController_search,viewController_setting, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
If you want to have a UITabBarController as your app's rootViewcontroller you can add this code to the didFinishLaunchingWithOptions function.
It adds a navigation controller containing a list controller and a simple view controller:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
UITabBarController* tabBarController = [[UITabBarController alloc] init];
UITableViewController* myListController = [[MyListController alloc] init];
UINavigationController* navigationControllerMyList = [[UINavigationController alloc] initWithRootViewController:myListController];
navigationControllerMyList.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
UIViewController* simpleViewController = [[SimpleViewController alloc] init];
simpleViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
tabBarController.viewControllers = #[ navigationControllerMyList , simpleViewController ];
self.window = [[UIWindow alloc] init];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

ios splitviewcontroller landscape fail

I have spliteview project and forced it in landscape mode.
It works fine before I upgrade my iOS SDK to iOS6.
But after upgrade, when I use iOS 5.1 Simulator to run, it always show in portrait mode and Master view is gone.
and here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
CustomverDetailViewController *custView = [[[CustomverDetailViewController alloc] initWithNibName:#"CustomverDetailViewController" bundle:nil] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = #[masterNavigationController, custView];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
Any ideas?
I try to give different code for different version, in iOS6 it seems ok, but in iOS5.1 still will changing orientation while I enter this view, I guess when I alloc an new UIWindow , it orginial orientation is portrait.
here I changed my code:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
left = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:left] autorelease];
right = [[CustomverDetailViewController alloc] initWithNibName:#"CustomverDetailViewController" bundle:nil];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = #[masterNavigationController, right];
if (([[[UIDevice currentDevice] systemVersion] floatValue ] < 6.0 )) {
self.splitViewController.delegate = left;
[self.splitViewController.view setFrame:CGRectMake(0, 0, 1024.0f, 768.0f)];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}else{
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
[right release];
Try to add new delegate method added in iOS 6
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (void)shouldAutorotate {
return NO;
}

tab bar controller can not display view controllers

Here my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
CSDisplayPlaza *displayPlaza = [[CSDisplayPlaza alloc] initWithNibName:#"CSDisplayPlaza" bundle:nil];
[displayPlaza setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"one" image:[UIImage imageNamed:#"displayPlaza"] tag:0]];
UINavigationController *displayPlazaNav = [[UINavigationController alloc] initWithRootViewController:displayPlaza];
CSGameHall *gameHall = [[CSGameHall alloc] initWithNibName:#"CSGameHall" bundle:nil];
[gameHall setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"two" image:[UIImage imageNamed:#"displayPlaza"] tag:1]];
UINavigationController *gameHallNav = [[UINavigationController alloc] initWithRootViewController:gameHall];
CSMyInformation *myInformation = [[CSMyInformation alloc] initWithNibName:#"CSMyInformation" bundle:nil];
[myInformation setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"three" image:[UIImage imageNamed:#"myInformation"] tag:2]];
UINavigationController *myInformationNav = [[UINavigationController alloc] initWithRootViewController:myInformation];
self.tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:displayPlazaNav,gameHallNav,myInformationNav,nil]];
[tabBarController setSelectedViewController:displayPlazaNav];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
In the simulator, cannot display any view controllers. Just a empty tabbar in my simulator. I don't know what happen.
My guess is displayPlaza is nil for some reason. Add log messages after you create every object to verify you in fact created one, and also the tab bar controllers array.

Resources