Making the Navigation controller in Detail view of Split View controller - ios

How can we programmatically create a Navigation controller in Detailed view of Split view based iPAd App?
I tried the steps, provided in this link, but could not replace the Detail view controller with Navigation controller in XIB.

I know this is an old question, but i hate questions that aren't answered.
UIViewController * masterController = ... allocation/init ...
UIViewController * detailController = ... allocation/init ...
UINavigationController *detailNavController = [[[UINavigationController alloc] initWithRootViewController:detailController ] autorelease];
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController .viewControllers = [NSArray arrayWithObjects:masterController , detailNavController, nil];

Related

How to display more than 4 tabs in a single row without having "More" option iOS [duplicate]

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.

UITabBar Showing More Icons Instead of "More" Option

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.

SplitViewController in only one of the existing 5 views?

I have 5 views in my app and I'm appDelegate by setting them in the following way:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationcontroller1, navigationcontroller7, navigationcontroller5, navigationcontroller4, navigationcontroller6, navigationcontroller2, nil];
self.window.rootViewController = tabBarController;
All of them come with a NavigationController and tabbarcontroller, But I needed to split the screen into two parts, in this case the screen would be divided would be navigationcontroller2, as you can see below:
VendaViewController *venda_viewcontroller = [[VendaViewController alloc] init];
UINavigationController *navigationcontroller2 = [[UINavigationController alloc] init];
[navigationcontroller2 pushViewController:venda_viewcontroller animated:YES];
Hence I tried the following way:
VendaViewController *venda_viewcontroller = [[VendaViewController alloc] init];
VendaDetailViewController *vendaDetail_viewcontroller = [[VendaDetailViewController alloc] init];
UISplitViewController *splitVC = [[UISplitViewController alloc] init];
[splitVC setViewControllers:[NSArray arrayWithObjects:venda_viewcontroller,vendaDetail_viewcontroller,nil]];
UINavigationController *navigationcontroller2 = [[UINavigationController alloc] init];
[navigationcontroller2 pushViewController:splitVC animated:YES];
But not work in this code, but in documentation of UISplitViewController is writing the following message:
"you must always install the view from a UISplitViewController object
as the root view of your application’s window. [...] Split view
controllers cannot be presented modally."
So...If I like to put a splitViewController in my view controller, I'll have to put splitViewController in all of my views controllers? Or have another solution to this?
You can use a UISplitViewController only as the root view controller of your app. In your case you can implement your custom container view controller with functionality similar to the split (two subview controller inside the main). Follow this link for details.

Load new View Controller from View Controller added as a subview

Hi I'm using the following library in my project https://github.com/firebaseco/FireUIPagedScrollView I've added a few view controllers as pages. My issue now is that when a user selects a button on one of my view controllers loaded as a page the page is simply replaced with my new view controller rather than the view controller holding the pages. Any one know how I can move to a completely new view controller when something is pressed on one of the pages?
The code I'm using to load my other view pager from the page is below
WebViewController *dvController = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]];
dvController.url = url;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:dvController];
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nc animated:YES];
Any help would be greatly appreciated
Simple solution ended up being create a property in the page and set it in the ViewController that has pages added to it
In Page.h
#property (nonatomic, retain) UINavigationController *navController;
In the Page Holding View Controller set the property equal to the holders navigationController
Page *pageVC = [[Page alloc] initWithNibName:#"Page" bundle:nil];
pageVC.navController = self.navigationController;
Then in Page.m when I wanted to push a new View Controller simply used the now set property when pushing the new View Controller
#synthesize navController
...
NewViewController *dvController = [[NewViewController alloc] initWithNibName:#"NewViewController" bundle:[NSBundle mainBundle]];
[self.navController pushViewController:dvController animated:NO];

UINavigationController is NULL

I've had a good look at the Apple docs as well as similar Stack Overflow questions, but I am stuck on why my navigationController is null when using tab bars. I am trying to build most of the app from code, and am not using XIBs to insert a navigationController.
While debugging I have greatly simplified my app, down to two tabs. One tab holds a tableview and when a row is touched I'm expecting a detail page (from a XIB) to appear. Should be pretty simple. I am finding the value of self.navigationController is NULL when attempting to push the detail view, and of course it is then not working. I took the tab bar our completely and it works fine from a single view (the tableview). In this instance self.navigationController has a value.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// With Tab Bars
self.tabBarController = [[UITabBarController alloc] init];
ViewController *vc1 = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
vc1.tabBarItem.title = #"Words";
vc1.tabBarItem.image = [UIImage imageNamed:#"tab_feed.png"];
TextTableViewController *vc2 = [[TextTableViewController alloc] init];
vc2.tabBarItem.title = #"Text";
vc2.tabBarItem.image = [UIImage imageNamed:#"tab_live.png"];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vc1];
NSArray* controllers = [NSArray arrayWithObjects:vc2, navController, nil];
tabBarController.viewControllers = controllers;
tabBarController.delegate = self;
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = self.tabBarController;
[window makeKeyAndVisible];
return YES;
}
From TextTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TextViewController *detailViewController = [[TextViewController alloc] initWithNibName:#"TextViewController" bundle:nil];
Text *text = [[Text alloc] init];
text = [textArray objectAtIndex:indexPath.row];
detailViewController.TextID = text.textID;
NSLog(#"Nav Controller: %#",self.navigationController);
[self.navigationController pushViewController:detailViewController animated:YES];
NSLog(#"pushed");
}
I've also got two questions related to this problem.
(1) What is the purpose of this line. It doesn't appear to make a difference if it is in or out, and is absent from the Apple example.
tabBarController.delegate = self;
(2) When creating an array of tabs, one of the views is made the navigationController. Does it matter which tab it is or should this be a different view altogether not related to any tab and not visible. Is this where the problem lies?
In answer to question (1) about the tab bar controller's delegate, see the UITabBarControllerDelegate protocol reference. For the basic functionality of a tab bar controller, you don't need to bother with a delegate.
But let's say you want to do something special--for instance, save a document or reset an interface element to a default value--when the user changes tabs. You could make one of your classes, perhaps your app delegate or another controller class, conform to the UITabBarControllerDelegate protocol and implement tabBarController:didSelectViewController:
In your "answer" you asked if each tab will need its own UINavigation controller. That is absolutely correct. Basically, each tab is a completely independent hierarchy, so you need a separate UINavigation controller in each tab that requires one.
This should also imply the answer to your question (2) in the original post. You need to add the nav controller to the specific tab(s) that needs it.
OK I found it. The UINavigationController needs to be contained within the appropriate tab of the UITabBarController. So by making this coding change (below), a new UINavigationController is embedded in the tab with the tableview.
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vc2];
NSArray* controllers = [NSArray arrayWithObjects:vc1, navController, nil];
Which then begs the question: what if you need multiple examples of this - do you create a new UINavigationController for each tab that has a need for one, and mark each one as a rootViewController?

Resources