Push a view from a TabBarController programmatically created - uitableview

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.

Related

Show Navigation Bar in Child View Controller

I am working on an app in which I have to display multiple view controllers side by side (split views). For this purpose I have added views as child view controller.
OBJECTIVE: I want to show navigation bar on one child view controller along with already shown separate navigation bar on parent view controller.
PROBLEM: Navigation bar doesn't get shown on child view controller.
EDIT: I have also set navigation bar of parent view controller as hidden but when child view controller get's called, the navigation bar gets appeared on parent view controller, not on child view controller.
Code to add child view controller is:
MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:#"MyChildViewController" bundle:nil];
[self addChildViewController:childViewController];
[childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
[self.rightContainerView addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];
This code is working fine and child view controller gets add perfectly. I want to know is it possible or not?
Thanks in advance.
I solved this problem by myself through following way:
MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:#"MyChildViewController" bundle:nil];
[childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:childViewController];
childNavController.view.frame = childViewController.view.frame;
[self addChildViewController:childNavController];
[self.rightContainerView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];
Now when I add navigation bar in MyChildViewController, it gets added in child view controller and does not affect navigation bar of parent view controller. The navigationController property of child view controller is also different than navigationController property of parent view controller and both have their own navigation stacks.
add Navigation bar like this
It will be appear in your all view controller
Another way to do:
Put this code into didFinishLaunchingWithOptions method in appdelegate.m file.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ECViewController * ec = [[ECViewController alloc] initWithNibName:#"ECViewController" bundle:nil];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:ec];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
Add a Nib file(ECViewController) by simply following these steps:
1: Right click in project root
2: Add new file
3: Go to user interface.
4: Select view
5: Give it name same as your view controller name i gave ECViewController in my case.
Click on newly created nib file
Click on file owner fist yellow box on left side. make an connection with view by simple dragging with control keyword.click on view when popup appear.
Now goto identity inspector (fourth section from staring in left side).
Write your class name in Class name textBox appeared.
By this you can able to open an xib in iOS7 if you don't want to use storyboard.
Now if you need view controller with navigation controller.
Then open your view controller by this way.
ECViewController1 *v = [[ECViewController1 alloc]initWithNibName:#"ECViewController1" bundle:nil];
[self.navigationController pushViewController:v animated:YES];
Its too late for this edited answer, Hope it will help someone other.
Set the y position of child view correctly.
MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:#"MyChildViewController" bundle:nil];
[self addChildViewController:childViewController];
[childViewController.view setFrame:CGRectMake(0.0f, 44.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
[self.rightContainerView addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];
I have found the link from stackoverflow we need to add navigation bar manually there is no alternate for this.

Add TabBArController to the UIView

Adding tab bar controller to the UIView by [self.view addSubview:tabBarController.view];
is not loaded the content view controllers view, while selecting the tab bar items it crashed. When set the tab bar controller to the root view controller its working fine. How to set tab bar controller into UIView so that I can set another view for some other purpose like iAd?
You just create one tabbar controller in app delegate but don't add it to window, and in view controller you have just add these:
gObjAppDelegate.tabBarController = [[UITabBarController alloc] init];
gObjAppDelegate.tabBarController.viewControllers = #[viewController1, viewController2];
[gObjAppDelegate.tabBarController setSelectedIndex:0];
[self.navigationController pushViewController:gObjAppDelegate.tabBarController animated:YES];
gObjAppDelegate is shared singleton instance of app delegate.This way it worked for me.

Adding a third Tab in Tab bar project

im new to iphone coding and i would like some help with a tab-bar project as i found on www.fuelyourcoding.com
He is creating a custom tabbar. He can then change color of the tab-bar instead of the standard grey color.
How can i Add a third tab? I have tried to create a "ThirdViewController" as the project contained a first and a second-viewcontroller. I've also tried to copy all the information i thought could affect the tabs, and inserted "ThirdViewController", where it previously said "SecondViewController" and so on.
It's hard to describe, but here is the link if someone would be kind to have a look at it.
http://fuelyourcoding.com/files/files.zip
Thanks!
In general, you create a tab bar controller and three view controllers. You add these three view controllers to the tab bar controller and add the tab bar controller as the root view controller of the app delegate. There's not a lot that can go wrong with this idea, but if you can show more code, that will be great.
Here's the example:
ViewController1 *v1 = [[ViewController1 alloc] init];
ViewController2 *v2 = [[ViewController2 alloc] init];
ViewController3 *v3 = [[ViewController3 alloc] init];
self.tabBarController.viewControllers = #[v1, v2, v3];
self.window.rootViewController = self.tabBarController;

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.

How to use UISplitViewController

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.

Resources