I am using am SWRevealViewController in my iOS 8.2 app. It works perfectly fine, but when my view displays though it a frosted navigation bar hangs around at the top of the screen, under the status bar. It is covering my background image, and I haven't found an easy way to remove it.
mainView = [[ViewController alloc] init];
sideMenu = [[MenuController alloc] init];
UINavigationController * frontViewController = [[UINavigationController alloc] initWithRootViewController:mainView];
UINavigationController * rearViewController = [[UINavigationController alloc] initWithRootViewController:sideMenu];
revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
revealController.delegate = mainView;
I searched through the SWRevealViewController code and didn't find anything obviously related to it. I tried commenting out suspicious sections of code and viewing the result. I hid the status bar. Nothing touched it.
I have tried a few things...
[frontViewController.navigationController setNavigationBarHidden:YES];
frontViewController.navigationController.navigationBar.frame = CGRectZero;
[frontViewController.navigationController.navigationBar setHidden:YES];
[revealController.navigationController setNavigationBarHidden:YES];
revealController.navigationController.navigationBar.frame = CGRectZero;
[revealController.navigationController.navigationBar setHidden:YES];
[revealController.navigationController.navigationBar setBounds:CGRectZero];
...to no effect.
As your front view is mainView you will be using
[mainView.navigationController setNavigationBarHidden:YES];
I hope this helps.
Upon completion of this question, I tried one final test.
[mainView.navigationController setNavigationBarHidden:YES];
This worked. It would appear that something in the process of embedding the mainView in the SWRevealViewController caused the navigation bar in the mainView itself to become visible, even though by default it was not.
Related
I have recently removed the tab bar from my app in favor of a "slide out" styled menu which I have written myself. It appears to be working perfectly, except that the one split-view controller I use in the app does not work correctly on the iPad in portrait orientation (landscape is just fine). The problem I'm seeing is the detail VC ONLY is loaded into the portrait view, where both VCs load correctly in landscape view. This is on iOS7.
So, here is the code I'm using. This code has been moved from the AppDelegate (previously) to the root VC. There were some changes but relatively minor. It did work fine with the tab bar, but using this new slide out menu (i.e., a table view) I have this one problem. I'm only including the portions of the code that I think would be relevant.
AdminMasterViewController *adminMasterVC = [[AdminMasterViewController alloc] init];
UINavigationController *adminMasterNav = [[UINavigationController alloc] init];
adminMasterNav.viewControllers = [NSArray arrayWithObjects:adminMasterVC, nil];
adminMasterNav.view.frame = CGRectMake(0,0,[Utility screenWidth],[Utility screenHeight]);
AdminDetailViewController *adminDetailVC = [[AdminDetailViewController alloc] init];
UINavigationController *adminDetailNav = [[UINavigationController alloc] init];
adminDetailNav.viewControllers = [NSArray arrayWithObjects:adminDetailVC, nil];
adminDetailNav.view.frame = CGRectMake(0,0,[Utility screenWidth],[Utility screenHeight]);
UISplitViewController *adminSplitVC = [[UISplitViewController alloc] init];
adminSplitVC.viewControllers = [NSArray arrayWithObjects: adminMasterNav, adminDetailNav, nil];
adminSplitVC.delegate = self;
adminSplitVC.title = #"Admin";
adminSplitVC.view.frame = CGRectMake(0,0,[Utility screenWidth],[Utility screenHeight]);
vcArray = [NSArray arrayWithObjects:homeVC, adminSplitVC, expressiveNav, receptiveNav, typerNav, nil];
(The last line builds the array of all the VCs in the project; the code which creates these VCs has been omitted).
After the VC has been selected it is presented as a child VC as follows:
UIViewController *vc;
if ([selected isEqualToString:#"Home"])
{
vc = [vcArray objectAtIndex:VCHome];
}
else if ([selected isEqualToString:#"Administrator"])
{
vc = [vcArray objectAtIndex:VCAdmin];
}
... (others listed here)
[self.view addSubview:vc.view];
[self addChildViewController:vc];
[vc didMoveToParentViewController:self];
From what I have read there may be some issue with NOT using the tab bar, but the articles are confusing because a lot of them are dated. I will appreciate any input or suggestions on this problem as I've read everything I can find and don't really know where to go from here. TIA.
After a couple of days of reading and trying different things, an hours after posting the question I solved this. Just in case anyone else hits this same problem, here's the solution:
I subclassed the UISplitViewController and made it its own delegate.
Then, this delegate method solved it:
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return NO;
}
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.
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
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];
In my iPad application, i have a main menu screen.. with various icons on it.
On tapping on an icon, it navigates me to Custom UISplitViewController. I did it with this code. Everything is working fine in SplitView.
Problem: I am facing issue to get back to my Main Menu screen on tapping a button in MASTER Viewcontroller's Navigation bar.
code for Custom UIsplitview:-
self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
left = [[LeftViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *leftNav = [[UINavigationController alloc] initWithRootViewController:left];
right = [[RightViewController alloc] initWithNibName:#"RightViewController" bundle:nil];
UINavigationController *rightNav = [[UINavigationController alloc] initWithRootViewController:right];
left.right = right;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNav,rightNav, nil];
splitViewController.delegate = right;
appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UISplitViewController *cvc = (UISplitViewController *) splitViewController;
[appDelegate.window setRootViewController:cvc];
EDIT: Custom button code
UIButton *a1 = [UIButton buttonWithType:UIButtonTypeCustom];
[a1 setFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[a1 addTarget:self action:#selector(menu:) forControlEvents:UIControlEventTouchUpInside];
[a1 setImage:[UIImage imageNamed:#"icon.png"] forState:UIControlStateNormal];
UIBarButtonItem *random = [[UIBarButtonItem alloc] initWithCustomView:a1];
left.navigationItem.leftBarButtonItem = random;
- (void)menu {
[self.view removeFromSuperview];
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[appDelegate.window setRootViewController:vc];
[vc release];
}
This causes CRASH, with EXC_BAD_ACCESS message.
Pls guide me..
I assume you can see which line of your code the crash happens on by stepping through from a breakpoint?
I'm not a fan of your sw design here to be honest as I wouldn't use a UISplitViewController subclass. I'd be more likely to create a custom SplitViewController using UIViewController containment APIs and then use that in conjunction with a UINavigationController.
That said, if you must use a UISplitViewController subclass then I would suggest having all your code to add or remove the viewControllers from the window in the main appDelegate and then use notifications to tell the appDelegate when to add or remove the relevant viewControllers (switch the root). This way you reduce the potential to have multiple instances of the same view controllers hanging around leading memory issues. It's always tricky to try to get a viewController to remove itself from it's parent, and is best managed by parent or higher level entity (in this case the main app delegate).
I'm not sure this is a good design. What else do you do from your main menu screen bedsides going to the split view controller?
If you want to keep this design, you would do the same thing you did at the end of your posted code -- in the button's action method, create an instance of your main menu controller and set it as the window's root view controller.
After Edit:
I can see one problem that's sure to create a crash -- when you create your button, you have the action set as "menu:", but your method implementation is just "menu" with no colon or arguments. Remove the colon, and everything should work.
I don't think these 3 lines are causing trouble, but there's no need to do what you're doing:
appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UISplitViewController *cvc = (UISplitViewController *) splitViewController;
[appDelegate.window setRootViewController:cvc];
You already have a property or ivar, splitViewController, there's no need to reassign it to cvc. Also there's no need to get the app delegate, you can get the window with self.view.window. So those 3 line can be changed to just this:
self.view.window.rootViewController = splitViewController;