i have the following problem.
I'm developing an app with a splitViewController as the root controller. In the appDelegate i have this code in method didFinishLaunchingWithOptions:
[self.window addSubview:splitViewController.view];
[self.window makeKeyAndVisible];
self.sendData = [[[SendData alloc] init] autorelease];
showEventsViewController.sendData = self.sendData;
LoginView *lvc = [[LoginView alloc] initWithNibName:#"LoginView" bundle:nil];
lvc.delegate = self;
[splitViewController presentModalViewController:lvc animated:NO];
[lvc release];
return YES;
When the login is complete, i dismiss the loginView and i show the splitViwController.
Besides, my application needs to run only in landscape mode, so i have configured the plist in order to avoid only landscape mode and set this code in each view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
return YES;
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
But when i run my app in portrait mode (the login view is shown right in landscape) and icomplete the login, the splitview is shown in landscape mode but the detailViewController is whole black (the master view is in landscape mode)
What is happening?
Thanks
Related
I would like to create an application like this:
On iphone (both portrait and landscape) and ipad portrait, I have a table view screen, tap on item row will navigate to another detail screen look like other basic application.
But when I rotate screen to go to landscape on ipad, the screen now has two section views
Here is what I did:
Write a method isInLandscapeTablet to detect ipad landscape
Use UINavigationController as a root controller to control all other views
In portrait screen, push a viewcontroller contains tableview to root controller
In landscape tablet screen, attach tableview controller and detail controller to UISplitViewController, then push it into root controller
But the problem is I can't push UISplitViewController to root controller, as it requires to be a root controller.
I wonder how I can handle this problem
And is my approach correct? Is there any other way?
Update: I change the root view controller like this
// this snippet is in UINavigationController (I use as root viewcontroller)
if([self isInTabletLandscape]){
self.splitViewController.viewControllers = [NSArray arrayWithObjects:[[CategoryViewController alloc] initWithNibName:#"CategoryViewController" bundle:nil], self.propertyLandViewController, nil];
[[UIApplication sharedApplication].keyWindow setRootViewController:self.splitViewController];
}else{
// it doesn't work
[[UIApplication sharedApplication].keyWindow setRootViewController:self];
}
}
After knowing the device whether it is iPad or iPhone. You Can try to remove the RootViewController.
appDelegate.window.rootViewController = nil;
Then you set the root view controller with a new SplitViewContloller
id objClass =[[SplitViewController alloc]initWithNibName:#"SplitViewController" bundle:nil];
masterVC.delegate = detailVC;
detailVC.delegate = objClass;
[objClass setViewControllers:#[masterNavigate,detailNavigate]];
[appDelegate.window setRootViewController:objClass];
My suggestion is not to use Split View Controller at all. Create a custom View Controller, which will embed your table view controller and the 2nd controller. Also, you can implement the interface-rotation logic in the custom controller you create.
If you are developing on iOS 8 you should use Size Classes, so you can totally change the layout depending on iPhone/iPad portrait and iPad Landscape. Unfortunately on iOS 7, size classes only differentiate iPhone and iPad.
In both case the right part (2), can be easily handle with a containerView.
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MyFirstViewController* firstVC = [[MyFirstViewController alloc] init];
MySecondViewController* secondVC = [[MySecondViewController alloc] init];
if ( ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) ){
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = splitVC;
[window makeKeyAndVisible];
}
else
{
// Display tableview
}
return YES;
}
I assume this may help you..
I'm trying to keep UITableViewcontroller in Portrait orientation. Hence, I don't want to rotate to Landscape mode. I added below method. But it didn't help, notice I'm using iOS 8:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if(interfaceOrientation== UIInterfaceOrientationPortrait)
{
return YES;
}else
{
return NO;
}
}
Notice, I'm calling the UITableView through UINavigationController
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:svc];
// configure the new view controller explicitly here.
[self presentViewController:navigationController animated:YES completion: nil];
You can set the enabled orientation interface in the Info.plist or, if you want only the Table in this way, you have to modify manually the supportInterfaceOrientation in the navigationController when you are presenting the view. The 'child' will assume the values from the navigationController. Then, when you dismiss the table, you have to reset the supportInterfaceOrientation manually.
I have a project for the iPad that I've made using iOS7 which displays at one point a view controller in landscape mode. On this view controller, there is a UITextField which is the first responder on the screen, and thus immediately when the user comes to this screen, the keyboard is supposed to be presented, which it does.
The problem however, is that the keyboard is being displayed in portrait mode, when the view controller is being displayed in landscape mode, in iOS 8. How do I correct this, so that the orientation of the keyboard is consistent with the view controller (which is still being displayed in landscape mode, correctly)? Just for the record, this view in particular is using a .xib file, and not in storyboard.
Below is the code that I have:
MyLandscapeViewController.m
relevant methods:
-(BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;
}
- (void)viewDidUnload {
[self setKeyboardButton:nil];
[super viewDidUnload];
}
For the view controller, I created a custom navigation controller:
MyNavigationController.m
-(BOOL)shouldAutorotate{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
From my application, it is called as follows:
MyLandscapeViewController *myView = [[MyLandscapeViewController alloc] initWithNibName:#"MyLandscapeViewController" bundle:nil];
MyNavigationController *navigationController = [[MyNavigationController alloc] initWithRootViewController:myView];
[self.rootViewController presentViewController:navigationController animated:YES completion:nil];
What changes do I need to make for this to work on iOS 8?
Try this.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:#"orientation"];
[UIViewController attemptRotationToDeviceOrientation];
}
I have using split view in my application.
When i run my application in iOS 6 simulator it rotates as per orientation changes and works well but when i run same application in iOS 5 or iOS 5.1 simulator and i change orientation of simulator but split view not changes as per orientation change.
I also add code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotate
{
return YES;
}
And I add split view using following code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
above method in both Master View and Detail View.
And I added split view using following code
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// obj_PageControlViewController = [[PageControlViewController alloc]initWithNibName:#"PageControlViewController-iPad" bundle:nil];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController_iPad" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
TabBarAppDelegate *appDelegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window setRootViewController:self.splitViewController];
}
but it's not work. Any one can help me?
You say you added shouldAutorotateToInterfaceOrientation: but you didn't say where you added it. To get autorotation of a UISplitViewController in iOS 5.1 or earlier, you must supply shouldAutorotateToInterfaceOrientation: in the view controllers of both child view controllers of the split view controller (both the master and the detail view controllers).
That will work, assuming that the split view controller is the top-level (root) view controller of your application, as set up by the Master-Detail template.
Oh, and save yourself some trouble: in shouldAutorotateToInterfaceOrientation:, just return YES. On iPad, you always want to autorotate.
In iOS5 and below you should use
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
The one you posted above (shouldAutorotate) is for iOS6+
I have a UIViewController that implements
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Then, I try to popup a modal on top of that view:
ModalViewController *modalViewController = [[ModalViewController alloc] init];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[mainViewController presentModalViewController:modalViewController animated:YES];
If I launch the modal while the ipad is in portrait, it works fine. But when I'm holding it in landscape and try to launch the modal, the modal appears half offscreen to the upper right of the ipad. Any ideas?
In ModalViewController, implement shouldAutorotateToInterfaceOrientation the same way that it is in mainViewController (both need to agree on the orientations they support).