A is a subclass of TabbarViewController
A *a = [[A alloc] init];
B *b = [[B alloc] init];
C *C = [[C alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:b,c, nil];
[a setViewControllers:viewControllers];
UINavigationController *nv =[[UINavigationController alloc] initWithRootViewController:a];
nv.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:nv animated:YES completion:nil];
And in A.m: I find the a.navigationController.navigationBar is nil
I dont know why?
Normally, you should create several NavigationController objects for each of TabBarController's tabs.
When you create a navigation interface, you need to decide how you intend to use a navigation interface. Because it imposes an overarching organization on your data, you should only use it in these specific ways:
Install it directly as a window’s root view controller.
Install it as the view controller of a tab in a tab bar interface.
Install it as one of the two root view controllers in a split view interface. (iPad only)
Present it modally from another view controller.
Display it from a popover. (iPad only)
If you still want 'TabBarController inside NavigationController' functionality, please, read this or this SO questions to find a proper solution.
Related
I'm currently attempting to use the UITabBar for an iOS app that contains 7 tabBar Items.
When I use the storyboard, I am able to achieve all 7 tabBarItems.
When I programmatically add the tabBarItems, It forces a "More" Button to access the other tabBarItems.
Is there a way programmatically keep all the 7 tabBarItems as when I am manually create the UITabBar?
The Code that I'm using to build the uitabbar in my appdelegate.m
self.tabBarController = [[UITabBarController alloc] init];
FirstViewController *firstVC = [[FirstViewController alloc] init];
SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
FourthViewController *fourthVC = [[FourthViewController alloc] init];
FifthViewController *fifthVC = [[FifthViewController alloc] init];
SixthViewController *sixthVC = [[SixthViewController alloc] init];
SeventhViewController *seventhVC = [[SeventhViewController alloc] init];
NSArray *controllers = #[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixthVC, seventhVC];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[_window addSubview:_tabBarController.view];
By design you are limited to 5, from apple docs
If you add more than five items to the viewControllers property, the
tab bar controller automatically inserts a special view controller
(called the More view controller) to handle the display of the
additional items. The More view controller provides a custom interface
that lists the additional view controllers in a table, which can
expand to accommodate any number of view controllers. The More view
controller cannot be customized or selected and does not appear in any
of the view controller lists managed by the tab bar controller. It
appears automatically when it is needed and is separate from your
custom content. You can get a reference to it though by accessing the
moreNavigationController property of UITabBarController.
It just not recommended , but if you insist you will need to use a library or perhaps use a tool bar and add many UIBarButtonItems to it.
I'm currently attempting to use the UITabBar for an iOS app that contains 7 tabBar Items.
When I use the storyboard, I am able to achieve all 7 tabBarItems.
When I programmatically add the tabBarItems, It forces a "More" Button to access the other tabBarItems.
Is there a way programmatically keep all the 7 tabBarItems as when I am manually create the UITabBar?
The Code that I'm using to build the uitabbar in my appdelegate.m
self.tabBarController = [[UITabBarController alloc] init];
FirstViewController *firstVC = [[FirstViewController alloc] init];
SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
FourthViewController *fourthVC = [[FourthViewController alloc] init];
FifthViewController *fifthVC = [[FifthViewController alloc] init];
SixthViewController *sixthVC = [[SixthViewController alloc] init];
SeventhViewController *seventhVC = [[SeventhViewController alloc] init];
NSArray *controllers = #[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixthVC, seventhVC];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[_window addSubview:_tabBarController.view];
By design you are limited to 5, from apple docs
If you add more than five items to the viewControllers property, the
tab bar controller automatically inserts a special view controller
(called the More view controller) to handle the display of the
additional items. The More view controller provides a custom interface
that lists the additional view controllers in a table, which can
expand to accommodate any number of view controllers. The More view
controller cannot be customized or selected and does not appear in any
of the view controller lists managed by the tab bar controller. It
appears automatically when it is needed and is separate from your
custom content. You can get a reference to it though by accessing the
moreNavigationController property of UITabBarController.
It just not recommended , but if you insist you will need to use a library or perhaps use a tool bar and add many UIBarButtonItems to it.
I am presenting a UITabBarController from another ViewController (HomeViewController). The TabBarController in turn contains UINavigationControllers. However, when from one of the navigation controllers, the user presses the home button, he is required to go to the original ViewController from where the TabBarController was presented.
**tabBarController is not the rootViewController of my window.
Here's my code.
In AppDelegate, I am creating and configuring my TabBarController.
self.custCareVC = [[CustomerCareViewController alloc] initWithNibName:#"CustomerCareViewController_iPhone" bundle:NULL];
self.POController = [[PurchaeOrderViewController alloc] initWithNibName:#"PurchaeOrderViewController_iPhone" bundle:NULL];
self.accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:#"AccountsAndContactsViewController_iPhone" bundle:NULL];
self.customerCareNavController = [[UINavigationController alloc] initWithRootViewController:self.custCareVC];
self.customerCareNavController.title = #"Customer Service";
self.purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:self.POController];
self.purchaseOrderNavController.title = #"PO";
self.accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:self.accAndContactsController];
self.accAndContactsNavController.title = #"Accounts And Contacts";
self.tabBarController = [[UITabBarController alloc] init];
//self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"bluehead.png"];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.customerCareNavController, self.accAndContactsNavController, self.purchaseOrderNavController, nil];
In my HomePageViewController, i am presenting it in the following way (on click of a button):
AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
appDel.tabBarController.delegate = self;
[self presentViewController:appDel.tabBarController animated:YES completion:NULL];
Now i need to dismiss my tabBarController after a user presses a Button on any of the navigation controllers (present in the tabBarController) and show the HomeViewController again..!!
You need to create a function in your target controller (which has the power to dismiss the tabBarController) and call that function from your topmost(current) controller/ controller the user is currently interacting with. To achieve the above, you need to first get the tabBarController object from the current controller using parent view controller. Then get the parent view/ root view controller of that controller and performSelector (function) which you created in the first controller.
Be sure to check doesRespondToSelector before you call performSelectorso as to avoid any nasty crashes.
Another way, though pretty hackie is to store a weak reference of the first controller in the AppDelegate and access the same from you current controller.
I have a UISplitViewController from which I need to load a UIViewController. I know I can do this as a modal, but that's not what I'm after. I need for the UIViewController to load like a normal VC occupying the full screen and when the DONE button is touched for it to return to the UISplitViewController. Thus far, when I've tried to do this it loads into one half of the UISplitViewController instead of replacing it.
So, my question is, "Is this even possible?" and if so, how? Currently I'm using the modal (PageSheet), which would be fine in Portrait orientation but just looks bad in Landscape.
Currently, my Split View is set up in the App Delegate via a tab bar as follows:
AdminMasterViewController *adminMasterVC = [[AdminMasterViewController alloc] init];
adminMasterNav.viewControllers = [NSArray arrayWithObjects:adminMasterVC, nil];
AdminDetailViewController *adminDetailVC = [[AdminDetailViewController alloc] init];
adminDetailNav.viewControllers = [NSArray arrayWithObjects:adminDetailVC, nil];
UISplitViewController *adminSplitVC = [[UISplitViewController alloc] init];
adminSplitVC.viewControllers = [NSArray arrayWithObjects: adminMasterNav, adminDetailNav, nil];
adminSplitVC.delegate = self;
adminSplitVC.title = #"Admin";
Then loaded with the tab bar.
I don't know why I just can't grasp the relationships of VCs to one another, apparently a missing chunk of brain matter.
why you don't want to use modal? you can have a full screen, just set up modal presentation style
YourUIViewController *viewController = (YourUIViewController*)[yourStoryboard instantiateViewControllerWithIdentifier:#"YourUIViewController"];
[viewController setModalPresentationStyle:UIModalPresentationFullScreen];
/*some additional logic if needed*/
[yourSplitViewController presentViewController:viewController animated:NO completion:nil];
For an iPhone app how can I create a tab view programmatically, preferably in Objective-C?
It's quite simple to create a UITabBar via the UITabBarController. The following example should work within your AppDelegate class.
App Delegate Interface
Firstly, within the interface, we'll define our UITabBarController.
UITabBarController *tabBarController;
App Delegate Implementation
Then, within the implementation file's application:didFinishLaunchingWithOptions: method, we'll then initialise our tab bar controller.
// Initialise our tab bar controller
UITabBarController *tabBarController = [[UITabBarController alloc] init];
Next, you need to create the view controllers that you want to add to the tab bar controller. We'll need to add some information into these to set the tab's title/icon, but I'll come back to that at the end.
// Create your various view controllers
UIViewController *testVC = [[TestViewController alloc] init];
UIViewController *otherVC = [[OtherViewController alloc] init];
UIViewController *configVC = [[ConfigViewController alloc] init];
As the setViewControllers:animated: method requires an array of view controllers, we'll add our view controllers to an array and then release them. (As the NSarray will retain them.)
// Put them in an array
NSArray *viewControllers = [NSArray arrayWithObjects:testVC, otherVC, configVC, nil];
[testVC release];
[otherVC release];
[configVC release];
Then simply provide the UITabBarController with the array of view controllers and add it to our window.
// Attach them to the tab bar controller
[tabBarController setViewControllers:viewControllers animated:NO];
// Put the tabBarController's view on the window.
[window addSubview:[tabBarController view]];
Finally, make sure you call [tabBarController release]; within your dealloc method.
View Controller Implementation
Inside each of your view controllers, you'll also want to set the title and icon for the tab within the init method as follows:
// Create our tab bar item
UITabBarItem *tabBarItem = [self tabBarItem];
UIImage *tabBarImage = [UIImage imageNamed:#"YOUR_IMAGE_NAME.png"];
[tabBarItem setImage:tabBarImage];
[tabBarItem setTitle:#"YOUR TITLE"];
This is how we have to create tabbar programmatically
UINavigationController *BandNavigationController3;
AudienceSettingsViewController *audienceSettingsViewView =[[AudienceSettingsViewController alloc]initWithNibName:#"AudienceSettingsViewController" bundle:nil];
BandNavigationController3 = [[UINavigationController alloc]initWithRootViewController:audienceSettingsViewView];
BandNavigationController3.tabBarItem.title = #"Settings";
BandNavigationController3.tabBarItem.image = [UIImage imageNamed:#"settings.png"];
[BandNavigationController3.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:4];
BandNavigationController3.navigationBar.hidden = YES;
[bandTabBarArray addObject:BandNavigationController3];
[BandNavigationController3 release];
[audienceSettingsViewView release];
[tabBarController setViewControllers:bandTabBarArray];
[bandTabBarArray release];