How to use UISplitViewController - ios

I'm trying to use a split view controller to show a navigation controller on the left and a table view on the right. I use this code in RootViewController's viewDidLoad:
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
Settings *settings = [[Settings alloc] init]; //Table view
MainView *main = [[MainView alloc] init]; //Table view
UINavigationController *nav_con = [[UINavigationController alloc] init];
NSArray *controllers = [[NSArray alloc] initWithObjects:settings, detailViewController, nil];
[nav_con pushViewController:settings animated:NO];
self.view = nav_con.view;
detailViewController.view = main.view;
I've tried like a million different ways of coding this, and this one comes the closest to correct. It displays the navigation controller in the left pane and the main view in the right. HOWEVER, in the left pane, at the top, there are two bars with a big black space between them. One of the bars in my nav controller's bar. How can I just replace the content of the left pane entirely with my navigation controller's view?

Settings and MainView better be subclasses of UITableViewController
the first object in controllers should be nav_con, not settings
delete the last two "view" lines,
and RootViewController should be a subclass of UISplitViewController and the instance that's being created should be set to window.rootViewController somewhere.
Also, it's fairly standard to do all this code external to viewDidLoad - makes me wonder what's being loaded as the view! Much easier to do all this in a nib file.

Related

What is the correct way to display multiple ViewController's view hierarchy in a Container ViewContorler?

Recently, I am working on a project which have multiple ViewControllers, the controllers's view hierarchy need to display on screen at same time, the link below(it is a picture) is my design.
http://www.lazycatdesign.com/stuff/question.png
MainViewController is a Container ViewController, I add the MenuViewController and PictureViewController to it like this:
// Create the controllers
MainViewContorller* mainVC = [[MainViewController alloc] init];
MenuViewController* menuVC = [[MenuViewController alloc] init];
PictureViewController* pictureVC = [[PictureViewController alloc] init];
// add MenuViewController to MainViewController as its child controller
[mainVC addChildViewController:menuVC];
[mainVC.view addSubview:menuVC.view];
[menuVC didMoveToParentViewController:mainVC];
// add PictureViewController to MainViewController as its child controller
[mainVC addChildViewController:pictureVC];
[mainVC.view addSubview:pictureVC.view];
[pictureVC didMoveToParentViewController:mainVC];
Menu View and Picture View is now displayed on screen, the problem is only the Picture View can response the UI Event(such as the Tap Gesture). It seems only the last view hierarchy I add to Container ViewController can response UI Event, why? and what is the correct way to display multiple ViewController's view hierarchy in a Container ViewContorler?
Finally, the problem is solved, as rdelmar said, I forget to set the frames to the subviews, apple's document View Controller Programming Guide for iOS (page 117) also mention this, the codes should be:
// Create the controllers
MainViewContorller* mainVC = [[MainViewController alloc] init];
MenuViewController* menuVC = [[MenuViewController alloc] init];
PictureViewController* pictureVC = [[PictureViewController alloc] init];
// add MenuViewController to MainViewController as its child controller
[mainVC addChildViewController:menuVC];
[menuVC setFrame:frameOfMenuView]; // set the correct frame to menu view
[mainVC.view addSubview:menuVC.view]; // add menu view as sub view to main view
[menuVC didMoveToParentViewController:mainVC];
// add PictureViewController to MainViewController as its child controller
[mainVC addChildViewController:pictureVC];
[pictureVC setFrame:frameOfPictureView]; // set the correct frame to picture view
[mainVC.view addSubview:pictureVC.view]; // add picture view as sub view to main view
[pictureVC didMoveToParentViewController:mainVC];

UITabBarController offsetting content at first sight

I'm having trouble with my UITabBarController in the sense that my first view of the first UIViewController is being offset about 20 pixels to the bottom. Whenever I tab around and/or return to the first view controller (same instance, not released), it's fine. It's only the first encounter.
My steps:
I am allocating and initializing a UITabBarController
I am allocating and initializing 3 instances of UIViewController
I am setting the viewControllers property to an array of the above mentioned 3 items
My code:
- (void)viewDidLoad {
[super viewDidLoad];
// Allocate and initialize view controllers
self.debtsViewController = [[DebtsViewController alloc] init];
self.debtsViewController.title = NSLocalizedString(#"Debts", nil);
self.debtsViewController.tabBarController = self;
self.conclusionsViewController = [[ConclusionsViewController alloc] init];
self.conclusionsViewController.title = NSLocalizedString(#"Entries", nil);
self.conclusionsViewController.tabBarController = self;
self.settingsViewController = [[SettingsViewController alloc] init];
self.settingsViewController.title = NSLocalizedString(#"Settings", nil);
// Assign to tabBarController
self.viewControllers = [NSArray arrayWithObjects:self.debtsViewController, self.conclusionsViewController, self.settingsViewController, nil];
}
Any ideas?
Screenshot: http://cl.ly/image/2E0S001d0Q2x (notice the black space just above the UITableViewController)
i solved this problem.
```
[tab setSelectedIndex:1];
[tab setSelectedIndex:0];
```
you can manually reset the offset by switch the tab bar after the tabbarcontroller initialized
Having a glance at your screenshot made me think, that actually you should have 3 UINavigationControllers inside the UITabBarViewController. Their navigationBars will be(almost) lookalike, but it will be 3 separate instances. What does 'Settings' have in common with 'Debts'? Why would they share same navigation?
The point of using UITabBarViewController is to have independent sections of the app. I strongly recommend you Apple's guide.

How to get Navigation bar inside UIPopover Controller

I am using a uipopover controller with navigation bar.Actually i want to have navigation bar inside the popover controller. i tried changing the background color of the navigation controller but it didnt look as i expected.The navigation bar buttons seems to be attached with the popover corners.Please find the screenshot attached.Below is my code which i used to create the popover.
WLViewBookmarkViewController * viewBookmarkViewController = [[WLViewBookmarkViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewBookmarkViewController.delegate = self;
UINavigationController *viewBookmarkNavController = [[UINavigationController alloc] initWithRootViewController:viewBookmarkViewController];
viewBookmarkNavController.navigationBar.backgroundColor = [UIColor colorWithRed:9/255.0 green:135/255.0 blue:46/255.0 alpha:1.0];
self.bookmarkPopoverController = [[UIPopoverController alloc] initWithContentViewController:viewBookmarkNavController];
[self.bookmarkPopoverController presentPopoverFromBarButtonItem:bookmarkButtonItem permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
animated:YES];
Please suggest if there are any other way to achieve this.
I would init the UIPopover controller with the UINavigationController directly
self.bookmarkPopoverController = [[UIPopoverController alloc] initWithContentViewController: viewBookmarkNavController];
Also try settings the content size of the popover by overriding -contentSizeForViewInPopover in the viewBookmarkViewController class to return a CGSize, you should get neater results this way.
I created a Xib in where i had a view for the controller which i had to add inside the popover.i added a table view and a navigation bar into the view.

Display UISplitviewController In a PopOverViewController

I was recently displaying a list of items to a user via a tableview in a popover when a button was tapped. The table was displayed sections and headers.
I'm experimenting now with different ways to display the information and I want to try display the data in a UISplitViewController. The left view is a tableviewcontroller with headings. The right view is also a tableviewcontroller with sub headings.
I still want the data to be provided in a popover manner but when I've tried this the popover appears with nothing in it. I've put breakpoints in the viewDidLoad methods of my left and right view for the SplitView. The breaks are being hit but nothing is displaying in my popover.
How can I display a UISplitView IN a PopoverController.
My Root View
- (IBAction)showPopover:(id)sender {
self.SVC = [[SplitViewContainerViewController alloc] init];
self.pickerPopover = [[[UIPopoverController alloc] initWithContentViewController:SVC] autorelease];
CGRect frame= CGRectMake(0,0, 0, 0);
[self.pickerPopover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:0 animated:NO];
LoadView Of SplitViewContainerViewController
- (void)loadView
{
UIView *view=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 750, 880)]retain];
self.view=view;
self.splitViewController = [[UISplitViewController alloc] init];
self.leftViewController=[[[LeftViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
self.rightViewController=[[[RightViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
self.splitViewController.viewControllers= [NSArray arrayWithObjects:self.leftViewController, self.rightViewController, nil];
[self.view addSubview:self.splitViewController.view];
self.contentSizeForViewInPopover = CGSizeMake(750,880);
[super loadView];
}
UISplitViewControllers do not work unless they are the root view controller of the window. In order to do something like this you are going to need to create a custom split view controller and use that instead of UISplitViewController.
From Apple's documentation:
A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application's window. The panes of your split-view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface.
You may want to start by looking at MGSplitViewController, however, be aware that there are some limitations in iOS 4 and below including the inability to correctly forward rotation and view appearance and disappearance events to the child view controllers.

Push a view from a TabBarController programmatically created

I have created a tab bar controller as follows:
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
NSMutableArray *tabsArray = [[NSMutableArray alloc] init];
//tab1: dive info
LogsDetailDive *logsDetailDive = [[LogsDetailDive alloc] initWithNibName:#"LogsDetailDive" bundle:nil];
[logsDetailDive initWithLogSelected:logSelected:siteSelected];
logsDetailDive.title = #"Info";
logsDetailDive.tabBarItem.image = [UIImage imageNamed:#"/images/logs.png"];
[tabsArray addObject:logsDetailDive];
//tab2: deco info
...
//tab3: equipment info
...
//tab3: computer info
...
tabBarController.viewControllers = tabsArray;
[logsDetailDive release];
[self.view addSubview:tabBarController.view];
This tab controller is pushed from a previous table view into the navigation controller.
What I'm trying to get now is to show another view pushed from a tableview in LogsDetailDive, but I really cannot understand what I am missing, since it doesn't work.
Can you suggest something?
Thanks
UITabBarController reference
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
So the bottom line, this should not be done, and will cause some problems. If you need a tabbar layout you should instead use a toolbar.

Resources