I'm opening a View from the navigationController, using the NVSlideMenuController. However, I haven't been able to show a Navigation Bar (which I definitely need).
I'm not familiar with NavigationControllers and after following a few tutorials, it still isn't clear enough to me how it works.
This is in the AppDelegate application didFinishLaunching:
IntroViewController* introVC = [[IntroViewController alloc] initWithNibName:#"IntroViewController" bundle:nil];
UIViewController *menuViewController = [[MenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; // Your menu view controller
UIViewController *contentViewController = (UIViewController*)introVC; // The initial content view controller
menuViewController.navigationController.navigationBarHidden = false;
NVSlideMenuController *slideMenuController = [[NVSlideMenuController alloc] initWithMenuViewController:menuViewController andContentViewController:contentViewController];
self.window.rootViewController = slideMenuController;
return YES;
I tried adding the code to put the navbarhidden to false and it doesn't seem to work. Is there something else I missed?
Any help is very appreciated!
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
self.window.rootViewController = navigationController;
This will set the UINavigationController as your root view controller. If you MUST use NVSlideMenuController (which I have 0 experience with but really don't think it is necessary), then you can do the first two lines I gave you, and set the navigationController as the root for the NCSlideMenuController.
I would recommend Apple's documentation for UINavigationController, it is an extremely useful thing to know:
https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
Related
I started using UITabBarController and it is great.
The thing is I have a few views that aren't accessed from the UITabBar
(either presented modal programatically or we want to have a button on the top to jump to them)
The thing is that I want to retain the Tab bar visible in these views.
From my understanding mixing presentViewController and UITabBarController is problematic.
How can I do that? Can I have "hidden" tab bar elements I can reference programatically?
Just to clarify with an example:
Views A,B,C,D are in the tab bar - via the storyboard - everything is peachy.
I NEED to have views E and F clickable from the top navigation (please don't suggest a sliding TabBar or a multiple line UITabBar).
I could just jump to E and F but I want the UITabBar to still be visible so the user can jump from E to A for example.
Just use the good old UINavigationController for every tab and just use [self.navigationController pushViewController:A animated:YES];
That's how the setup looks in code:
SGTabBarViewController *rootVC = [[SGTabBarViewController alloc] init];
SGFirstTabViewController *firstVC = [[SGFirstTabViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:firstVC];
SGSecondTabViewController *secondVC = [[SGSecondTabViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondVC];
SGThirdTabViewController *thirdVC = [[SGThirdTabViewController alloc] init];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdVC];
SGForuthTabViewController *fourhtVC = [[SGForuthTabViewController alloc] init];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:fourhtVC];
rootVC.viewControllers = #[navController1, navController2, navController3, navController4];
self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];
If you want your UITabBar visible on every VC you push just use hidesBottomBarWhenPushed = NO; on it.
However, there is no way to have UITabBar visible on views presented modally.
Having one main navigation controller in whole application and also one main tabbarcontroller , problem is that when i click om 'more' tab of tabbarcontroller at that time it's showing two navigation bars
to solve this problem i tried to hide my main navigation controllers navigationbar using following code :
self.tabbar.navigationController.navigationBarHidden =YES;
but doing this gives me unexpected result in the form of half navigationbar with half black background.
if any one knows the solution then please help me.
thanks in advance.
make viewController With separate UINavigationController,
put this code in Appdelegate
ViewController *a = [[ViewController alloc] initWithNibName:#"a" bundle:nil];
ViewController *b= [[CreateMeetingViewController alloc] initWithNibName:#"b" bundle:nil];
ViewController *c = [[SettingsViewController alloc] initWithNibName:#"c" bundle:nil];
UINavigationController *nav_1 = [[UINavigationController alloc] initWithRootViewController:a];
UINavigationController *nav_2 = [[UINavigationController alloc] initWithRootViewController:b];
UINavigationController *nav_3 = [[UINavigationController alloc] initWithRootViewController:c];
MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate = self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:nav_1,nav_2,nav_3,nil]];
MainTabBar.view.frame=self.view.frame;
[self.view addSubview:MainTabBar.view];
You can check your .Xib you check the option Top Bar this should be 'None' in the identity inspector.
Write in viewWillAppear, i hope it will be helpful for you
[self.navigationController setNavigationBarHidden:YES animated:YES];
I'm just trying a really simple example here as I start to delve into iOS development for ipad.
I'm creating a split view and immediately trying to present a modal form sheet.
Should be really basic.
With what I've tried I get what behaves like a page sheet instead.
In landscape I can see the split view beneath but I don't see the top of my modal view (the tool bar is hidden but is in view in portrait).
I would expect to just grey out the split view beneath a 540x620 modal dialog. I should see the split view beneath my modal in both portrait and landscape like all the nice form sheet dialogs in the Cheddar app for example.
I must be doing something wrong here but all the examples I've read and same within the Cheddar app are doing pretty much what I outline below.
In the app delegate:
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
self.window.rootViewController = self.splitViewController;
[self.window addSubview:self.splitViewController.view];
ModalViewController *modalView = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:modalView];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self.splitViewController presentViewController:navController animated:NO completion:nil];
The app delegate is way too soon. You have no interface yet, so you can't coherently do any presenting of any view controller.
So, first thing, move all your modalView code to the viewDidAppear: of your detailViewController.
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?
I'm stuck on a problem I really don't know how to solve:
I have a TabBarController defined in my AppDelegate.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
In this TabBarController i have several other NavigationControllers which have UiVieController inside:
ProgramController *programContr = [[ProgrammController alloc] init];
UINavigationController navControllerPro = [[UINavigationController alloc] initWithRootViewController:programContr];
ManualController *manualContr = [[ManualController alloc] init];
UINavigationController navControllerMan = [[UINavigationController alloc] initWithRootViewController:manualContr];
and i add the NavigationController to the TabBarController:
tabBarController.viewControllers = [NSArray arrayWithObjects:navControllerPro,navControllerMan, nil];
I set the tabBarController to the rootViewController:
self.window.rootViewController = tabBarController;
[[self window] makeKeyAndVisible];
That works fine.
Now i want to add a "Login Screen" on top of that.
I did this with:
[tabBarController presentModalViewController:navControllerLogin animated:YES];
Now the TabBarController loads its content in the background even if the LoginViewController is in front. How to load the TabBarController only if a Button is pressed on the LoginViewController?
Please help me.
The tab bar controller is loaded everytime beacuse you set it as the rootViewController.
You should set a normal viewController as the root.. and if the login was succesfull the you should call the tabBarController to be loaded.
In other words, in the appDelegate there should be only the login window.. and in the loginViewController, if the login was ok, you should call and load your tabBarController with all its controller.. using storyboard makes it a lot easier.