In principle I want to implement a split view.
But I need the master to pop up not only in portrait orientation but in landscape orientation as well. Consequentally I do not want the view to be split at all in landscape orientation.
What is a proper way to implement that?
Is is smart using a split view at all or would you guys suggest an alternative approach?
You can do this in iOS 5 using the UISplitViewControllerDelegate method splitViewController:shouldHideViewController:inOrientation:.
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return (vc == myMasterViewController);
}
If you need to support iOS 4 then you will need to create a custom split view controller or use something like MGSplitViewController.
However, I would only do this if you are going to in fact show two view controllers split on the screen at once. This, really, is the main purpose of a split view controller. It sounds like you might not really need a split view controller, so I would consider just handling the popover yourself by presenting a UIPopoverController of your master view controller from a button on your navigation bar. Then you can just use a standard UINavigationController as your root view controller.
MGSplitViewController will allow you to do this:
https://github.com/mattgemmell/MGSplitViewController
Related
I want to implement my own container view controller.
Pls, imagine that this is my ipad
Kind of usual split view controller, but I want to extend it: width of view "a" should be resizable, when I tap view 'B' - view 'C' goes to visible area
For instance in my storyboard, I have 3 container views: AViewController (for A view), BViewController,CViewController and one combined view controller (initial view controller).
In combined view controller i will implement embed segues from container view and initialize relationship between container views via following code:
#property ... *aViewController,*bViewController,*cViewController;
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
if ([segue.identifier isEqualToString:#"EmbedAViewController"])
{
self.aViewController =
segue.destinationViewController;
}
if ([segue.identifier isEqualToString:#"EmbedBViewController"])
{
self.bViewController=segue.destinationViewController
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.aViewController.bViewController=self.bViewController;
}
Question1: Is it proper way implement my assignment using storyboards?
Question2: What kind of limitations does container view have? Is it a visual replacement of addChildViewController API? If no, where should I implement child-parent relationship? I should use in my combined view controller in prepareForSegue method
[self addChildViewController:aViewController];
[self.view addSubview:aViewController.view];
Question3: How to put container view outside of visible area at the beginning?
If I somewhere did a mistake or have a big misunderstanding of basic concepts, do not beat me. I did a lot of google-foo, I would really appreciate any help. Great thanks in advance!
Edit:
I want to set up relationship between all of them. "B" view's content depends on "A", and "C" view's content depends on "B".
I think you do have some misconceptions. If you want to implement container view controllers in a storyboard, you don't need to do anything in code. Start with one controller, the one you're calling combined view controller, and drag in 3 container views. Initially, you might want to size them so they are all full height, and make them all fit side by side in the main view. You can then change their sizes and positions using the size inspector, so that C's view starts at the right edge of combine controllers view, that way it will be off screen to start with. You will automatically get three view controllers connected to their respective container views with an embed segue. All three of these controllers will be instantiated at the same time as combined controller. You will need outlets in combined controller to each of its container views, so that you can resize them as necessary in code.
I'm working in Xcode 4.2 and am developing an app where I want the menu screen to use a Split View. Really, all I need the Split View Controller for is to split some of the menu options into a left pane and right pane. I want to be able to set custom sizes for the master and detail view controllers, but nothing seems to be working for me. I've tried updating the frame sizes for each view controller with code like:
[self.view setFrame:CGRectMake(0, 0, 768, 502)];
in the viewDidLoad functions, but that doesn't seem to affect anything.
Is there a way to set custom sizes for the master and detail view controllers of a split view controller without instantiating the view controllers in say the AppDelegate.m file? I want to be able to edit each of the view controllers in the storyboard as they are menu screens with a lot of buttons and such.
Edit:
In iOS 8+, the relative widths can be changed by specifying the minimum/maximumPrimaryColumnWidth properties or the preferredPrimaryColumnFraction.
The below answer is still true for iOS < 8:
You can't change the sizes for a split view controller.
See here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
"The UISplitViewController class is a container view controller that manages two panes of information. The first pane has a fixed width of 320 points and a height that matches the visible window height. The second pane fills the remaining space."
Use MGSplitViewController. It offers similar API to UIViewController, but offering additional features, such as split position, which is what you need.
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
return proposedMinimumPosition + 238;
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex;
{
return proposedMaximumPosition - 200;
}
before the above delegate method add [splitView addDelegate:self];
I am trying to develop an application that has screen flow similar to oracle app. I have attached the images here. Can anyone please tell how this can be achieved ?
Thanks in advance.
What you are looking for is a custom Split View Controller. The screenshots you provided are of custom split view controllers. The UIKit has UISplitViewController but this must be a fullscreen view controller.
To make a custom split view controller there's the old way, by having a main view controller and making your two master and detail controllers, adding their view to the main view controllers view.
You need to forward on calls from viewWillAppear:, viewWillDisappear: etc from the main view controller to the two controllers that you manage.
As of iOS 5, you can do something similar with view controller containment, this has a few more bells and whistles, more interesting it handles rotation animations better and all the call forwarding to the children controllers that you had to do manually in the first solution.
Check out this link for more details on custom split view controllers:
http://www.mindtreatstudios.com/how-its-made/custom-uisplitviewcontroller-ios/
To answer your question directly: if you make a custom split view controller - yes you can add this as a detail view controller. But watch out, this isn't a UISplitViewController, so just be careful not to use that term so much.
Haven't really tested this, but doesn't this solve your problem?
Create a storyboard file
Drop in a SplitViewController
Delete the DetailViewController
Drop in another SplitViewController
Link the two together using CTRL-drag and select Detail
Set the size of the detail-splitviewcontroller to Detail
????
Profit!
Anyways, not sure if it really works, but give it a try. This is IOS5 though (I think, might try it out with IB).
It'll look something like this:
If you're going to have to write your own class, you might want to first look at https://github.com/mattgemmell/MGSplitViewController for inspiration.
I am a beginner in objective-c. Can anyone please tell me how can I switch from one view to another in an iPhone application.
View Programming Guide for iOS
iPhone View Switching Tuturial
How To Switch Views using Multiple Viewcontrollers (Method 1)
Switching Views with Animation
How to animate View swap on simple View iPhone App?
switch between uiviews with buttons and not uinavigation controllers
Switch between UIViewControllers using UISegmentedControl
There are 3 main controllers that can switch views for you:
UINavigationController
Here you push and pop views in a chain.
There will be a navigation bar on top which lets you navigate back to where you came from.
UITabbarController
Here all the views will be represented by tabs at the bottom of the screen.
You can switch back and forward between them by clicking them in the tabbar.
UIViewController
There is a method in UIViewController wich lets you "present" other viewcontrollers. It's called presentModalViewController:animated:
You will have to do your own navigation back to the parent by using dismissViewControllerAnimated:
You can also do your own switching with variations of addSubView: or view.hidden or similar, but I would recommend those 3 to begin with.
I have a view controller that controls the switching between views. I would like one of the views to signal the view controller to switch to another view (and can't figure out how I can do this.)
To be more clear (hopefully): My view controller inserts a subview. That subview has a UITableView. I'd like, when you select a row in the UITableView, to remove the current subview and then switch to a different sub-view. Of course, I'd prefer the view controller to continue to keep track of which subview is loaded.
Does this make sense? (I'm still pretty green with Objective-C.)
Is there a way to send the view controller a message from the sub-view (that the view controller created)? Is there another way to accomplish this?
Thanks a bunch for the help... and I'd be happy to clarify if needed.
You might look into setting up a UINavigationController. Use the 2 UIViewControllers to control the individual views, and use the Navigation Controller to switch between the 2 views. From the UITableView, you can simply implement the method -
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Use this method to alloc the new view controller that you want to display
Then call the Navigation controller to push the new view controller onto the stack -
[self.navigationController pushViewController:controllerName animated:YES]
Finally, release the view controller that has disappeared.
This way the navigation controller keeps track of who is loaded, and can implement convenience functions like animating the transition. Also make sure to lookup the UITableViewController subclass - it is a subclass of UIViewController, but it provides some convenience functions for dealing with tables, like knowing when the user selects a particular row, and allows for the standard edit functions of most iOS apps.