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;
}
Related
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.
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
I am trying to create an application with a UITabBarController. I have followed several tutorials online and it seems like I'm missing something since my UITabBarController does not have text but you can switch from one View to another.
Here is my didFinishWithLaunchingOptions function:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
ListViewController *listVC = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
self.tabController.viewControllers = [[NSArray alloc] initWithObjects:viewController1, listVC, nil];
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];
[self createCopyOfDatabaseIfNeeded];
return YES;
}
What am I missing out on?
You need to set the tab bar image and title of each view controller:
self.tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
ListViewController *listVC = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
viewController1.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"VC1" image:[UIImage imageNamed:#"tab_ yourViewController.png"] tag:0];
listVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"listVC" image:[UIImage imageNamed:#"tab_listvc.png"] tag:1];
self.tabController.viewControllers = [[NSArray alloc] initWithObjects:viewController1, listVC, nil];
It's also possible (and often preferred) to set the tabBarItem for each view controller in viewDidLoad, I.e.:
- (void)viewDidLoad
{
[super viewDidLoad]; // Be a good citizen!
self.tabBarItem = [[UITabBarItem alloc] init...];
...
You can set tabbar item for each view with code
UITabBar *tabBar = self. tabController.tabBar;
UITabBarItem *tabBarItem0 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:1];
[tabBarItem0 setTitle:#"title1"];
[tabBarItem0 setImage:[UIImage imageNamed:#"img1"]];
[tabBarItem1 setTitle:#"title2"];
[tabBarItem1 setImage:[UIImage imageNamed:#"img2"]];
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];
i have an app for both iphone and ipad.
a classic master/detail app for iphone and splitview for ipad.
I want to add a slide out menu using MMDrawerController Github
I manage to add it for iphone but i d'ont understand how to add it for ipad and to keep the splitview / NavigationController behavior.
Original code :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
MyMasterViewController *masterViewController = [[MyMasterViewController alloc] initWithNibName:#"MyMasterViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
} else {
MyMasterViewController *masterViewController = [[MyMasterViewController alloc] initWithNibName:#"MyMasterViewController_iPad" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
MyDetailViewController *detailViewController = [[MyDetailViewController alloc] initWithNibName:#"MyDetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
}
[self.window makeKeyAndVisible];
Trying to use MMDrawerControler :
UIViewController * leftSideDrawerViewController = [[MMExampleLeftSideDrawerViewController alloc] init];
NSString *strViewMaster = #"MyMasterViewController_iPhone";
UIViewController * centerViewController = [[MyMasterViewController alloc] initWithNibName:strViewMaster bundle:nil];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
strViewMaster = #"MyDetailViewController_iPad";
centerViewController = [[MyDetailViewController alloc] initWithNibName:strViewMaster bundle:nil];
}
// unused
//UIViewController * rightSideDrawerViewController = [[MMExampleRightSideDrawerViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
MMDrawerController * drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController];
[drawerController setMaximumRightDrawerWidth:200.0];
[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModePanningNavigationBar];
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block){
block(drawerController, drawerSide, percentVisible);
}
}];
//centerViewController.mm_drawerController = drawerController;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:drawerController];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
So, on the ipad, the slide out menu is working, the detailview is loaded but i don't know how to define the masterViewcontroller / navigationcontroller so it does not work..
(sorry, i m a real nood with objective c and ios concept like you can see)
thank you
#picolo
Unfortunately, Apple enforces a UISplitViewController to be the rootViewController of a window, which means you can't place it inside a container view controller. You'll have to write your own similar split view controller implementation in order to drop it in another container view controller.
Cheers
MMDrawer Doesn't works with SplitViewController. Try using MFSlideMenu. It works with almost all types of controllers.
here is the link. --> MFSlideMenu
The MMDrawerController will not work with a SplitViewController. (as said int the github project description).
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.