In my app I have taken tabbar as a child view in my Homeviewcontroller screen using following code:-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = #"Home";
UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:#"tabbar"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0,60, self.view.bounds.size.width, self.view.bounds.size.height-200);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
}
but my problem is, it shows the first tab active, and show the first tab content on Homeviewcontrller screen, but i don't want to any tab active on Homeviewcontrller , i only want to show tabbar on Homeviewcontrller. and when i click any tab it will show appropriate screen.
Is there any solution on that in objective-C?
That is not how UITabBarController works. There must always be one active tab, and corresponding view controller displayed.
You could add your HomeViewController to the UITabBarController and show its tab when app starts. Then you can switch between all the tabs including home.
Related
I have a Tabbarcontroller filled with 5 Viewcontrollers and Navigationcontrollers as I did here:
[self addChildViewController:VC1];
[self addChildViewController:NavigationController;
[self addChildViewController:VC2];
[self addChildViewController:VC3];
[self addChildViewController:VC4];
Now the thing is, that pressing a button on my Tabbar gets me to every ViewController easily, where I can present Xib-Files etc.
But now I want to have a Navigationcontroller, which is shown when pressing a button on my Tabbar. This Navigationcontroller itself has several Viewcontrollers.
I tried this to present my first Viewcontroller inside my Navigationcontroller (this code is from the Navigationcontroller.m):
- (void)viewDidLoad {
[super viewDidLoad];
[self addChildViewController:VC5];
[self presentViewController:VC5];
}
This expectedly did not work and gave me: Application tried to present modally an active controller.
Is there a good way to achieve such a specific goal? I'm struggling with this problem. Thanks in advance!
edit: This is how I set it up in my storyboard. In my programmatic approach the first view controller is not shown.
Instead of adding the VC5 view controller to the NavigationController as a child (unless it's meant to be a child?) add it as the root view controller when you add the NavigationController to the tab bar.
For example in your tab bar code:
[self addChildViewController:VC1];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:VC5];
[self addChildViewController:navigationController];
[self addChildViewController:VC2];
[self addChildViewController:VC3];
[self addChildViewController:VC4];
Apple docs on UINavigationController are here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/#//apple_ref/occ/instm/UINavigationController/initWithRootViewController:
I want to show a controller as pop-up on click of a button. Suppose I have VC1 that has button, then on click of that the VC2 should load as a pop up. It is working to some extent. But I don't' know for what reason the VC2 is loading twice and the second time it loads it shows black background. Here is my code:
On click of button below function gets called in VC1,
VC2* childVC = [[VC2 alloc]init];
childVC.view.hidden = YES;
[self addChildViewController:childVC];
[self.view addSubview:childVC.view];
[self performSegueWithIdentifier:#"goToVC2" sender:self];
In VC2 viewdidload,
self.view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
How can I make VC2 appear as a pop up properly?
You don't need to segue and add the child view controller's view to the current view controller's view hierarchy. You should do one or the other. I would suggest the segue as that is a more apple approved approach. So change this:
VC2* childVC = [[VC2 alloc]init];
childVC.view.hidden = YES;
[self addChildViewController:childVC];
[self.view addSubview:childVC.view];
[self performSegueWithIdentifier:#"goToVC2" sender:self];
to
[self performSegueWithIdentifier:#"goToVC2" sender:self];
My iOS application is based on John-Lluch's SWRevealViewController to get sidebar navigation. I have ran into a navigation problem that I don't know how to solve.
I want one of the menu items to lead to a page that doesn't contain a sidebar but a back button instead. (The other menu items leads to pages where the sidebar can be opened).
To get a back button on a view I need to use a Show Detail Segue, but I also need a navigation controller "somewhere" for the back button to show up. (I don't mean that I need a navigation controller AFTER the segue - I have that already - but I need it somewhere before).
Have someone used SWRevealViewController in this way or know how to achieve this? "Where" should I place a navigation controller?
Thanks!
The only working solution I came up with was to use a Category on UIView, that could do my Detail Segues.
#interface UIViewController (SidebarView)
(void)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer;
(void)openSettingsPage;
(void)openAboutPage;
#end
and the .m-file's code for openAboutPage:
/* This method is called by the sidebar. If the sidebar opens the settings page from itself, the back button
* doesn't know where it should point. This method opens the about menu when the sidebar tells it to, and the back button
* is pointing to the home page. */
- (void)openAboutPage {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *about = [storyboard instantiateViewControllerWithIdentifier:#"About"];
[self.revealViewController rightRevealToggleAnimated:YES];
[self.navigationController pushViewController:about animated:NO];
self.navigationController.navigationItem.title = #"About";
}
and the setupSideBarWithGestureRecognizer... method
- (void)setupSidebarWithGestureRecognizer:(BOOL)useGestureRecognizer {
SWRevealViewController *revealViewController = self.revealViewController;
if (revealViewController) {
UIBarButtonItem *sidebarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"reveal"] landscapeImagePhone:[UIImage imageNamed:#"reveal"] style:UIBarButtonItemStylePlain target:self.revealViewController action:#selector(rightRevealToggle:)];
self.navigationItem.rightBarButtonItem = sidebarButton;
if(useGestureRecognizer) {
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
}
}
Then for each page I want to show a sidebar, I just call [self setupSidebar:YES]; in the viewWillAppear method of that view controller.
I have a UITabBarController as my root view controller for my app. It has 6 tabs but the app has a custom popup view with 6 buttons used to selected each of the tabs. The tab bar itself is hidden at all times.
The problem is once I try to programmatically select a tab at index 5 or 6 I get an issue. Tabs 1-4 are fine, they get selected in code and the new view controller appears on screen. But since tabs 5 & 6 are technically in the "more" tab, the tab bar appears briefly, shows animation to select the "more" tab and then disappears again. This also puts these "extra" view controllers in a new navigation controller with the "more" table view as the root view controller. This adds a new navigation bar and causes other issues.
Is there any way to do any of the following?
Have more than 5 tabs in a tab bar without the "more" tab.
Disable the "more" tab bar selection animation and the addition of the associated navigation controller.
Create a simple custom controller that could replace the UITabBarController entirely.
It seems like there are a lot of situations where one would want to show more than 5 tabs and yet hide the tab bar but I couldn't find anyone discussing this issue.
According to your requirements, I think you need a custom tabar controller.
This project may help you:
RDVTabBarController
Besides, I must warn you that using custom tabbar controller you may lost the chances to use the convenient features that system tabber contrller provides.
You should use the custom tabbar controller only if the system tabbar controler doesn't fit you needs.
Try the code below . The ViewController used here is a sub class of UITabBarController. In the .h file add ITabBarDelegate , UITabBarControllerDelegate.I guess this way you can add 6 tabs. I have done two tabs here and transition with animation. Use the delegate method
(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
as shown below to apply animations.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
fvcontroller = [self.storyboard instantiateViewControllerWithIdentifier:#"navcontroller"];
svcontroller = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
NSMutableArray *viewcontrollers = [[NSMutableArray alloc]init];
[viewcontrollers addObject:fvcontroller];
[viewcontrollers addObject:svcontroller];
[self setViewControllers:viewcontrollers];
fvcontroller.tabBarItem = [[UITabBarItem alloc]initWithTitle:#"Me" image:[UIImage imageNamed:#"me.png"] tag:1];
svcontroller.tabBarItem = [[UITabBarItem alloc]initWithTitle:#"Chat" image:[UIImage imageNamed:#"chat3.png"] tag:2];
// _tbbar.delegate = self;
self.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
UIView *from = self.selectedViewController.view;
UIView *to = viewController.view;
NSInteger fromindex = [self.viewControllers indexOfObject:self.selectedViewController];
NSInteger toindex = [self.viewControllers indexOfObject:viewController];
[UIView transitionFromView:from
toView:to
duration:.5
options:UIViewAnimationOptionTransitionFlipFromBottom
completion:^(BOOL finished) {
if (finished) {
tabBarController.selectedIndex = toindex;
}
}];
//(toindex > fromindex ? UIViewAnimationOptionTransitionCurlUp : UIViewAnimationOptionTransitionCurlDown)
return NO;
}
#end
i'm implementing a project with XCODE 5 and storyboard. I have added a view that is a UIPageViewController and when i alloc the first page (for this pageviewcontroller) the view appears normally but from second page the view appears under the navigation bar. What is the matter?
If i set this property
self.navigationController.navigationBar.translucent = NO;
for the view displayed the problem is solved but when i go back from Page View Controller to previous View, the buttons on it are shifted down.
Why? What is the solution?
Furthermore if i set translucent = NO the views displayed in storyboard are different from views displayed in my app (the views are not shifted in storyboard).
I can't post images because i'm not authorized.
This is the code of my PageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
variabiliGlobali = [foaGlobalVariable sharedInstance];
variabiliGlobali.giornataCalID = 1;
numeroGiornate = [variabiliGlobali.calendario count];
self.dataSource = self;
foaGiornataViewController *initialView = [[foaGiornataViewController alloc] init];
// Do any additional setup after loading the view.
[self setViewControllers:[NSArray arrayWithObject:initialView]
direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
}
The foaGiornataViewController is a view that doesn't exist on storyboard but is only a objective-c class.
Thanks in advances.
I have solved. I have setted opaque navigation bar for my Navigation Controller on storyboard.