tabbar is not displaying in secondview controller - ios

I am new in iOS world.I am creating one tab-bar sample app.
There is one button in first view-controller when i click this button it goes to to second view-controller.In second view-controller i use one gridview and i left 100 space at bottom.
now in second view-controller i have to add one tab bar so i go to Editor->Embedin->Tabbar controller and run application but i do not see tab bar here.I also try to use tab bar controller on object library but same issue i found.
Why tab bar is not displaying in second view-controller.Any suggestion ?
button click event :-
SecondVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:#"SecondVC"];
[self.navigationController pushViewController:vc animated:YES];
Thanks .

If you have the SecondVC embedded in a TabBarVC you need to present the TBVC instead of the SecondVC in order for the Tab Bar to actually appear.
So instead of doing:
SecondVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:#"SecondVC"];
[self.navigationController pushViewController:vc animated:YES];
you need to do:
TabBarVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:#"TabBarVC"];
[self.navigationController pushViewController:vc animated:YES];
This will add to the navigation stack the Tab Bar View Controller.
This might be the implementation you are looking for

Button to viewcontroller SecondVC set segue identifer name as Pass
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{if ([[segue identifier] isEqualToString:#"Pass"])
{
SecondVC* vc = [[SecondVC alloc] init];
vc = (SecondVC ) [[(UINavigationController)[[self.tabBarController viewControllers] objectAtIndex:0] viewControllers] objectAtIndex:0];
}
}

Related

back button navigation very slow

I am using following code to push viewcontroller from another viewcontroller .
ProductDetailViewController * productDetails = [self.storyboard instantiateViewControllerWithIdentifier:#"ProductDetailViewController"];
[self.navigationController pushViewController:productDetails animated:YES];
Now this is the code gets called on tap of back button
[self.navigationController popViewControllerAnimated:YES];
Problem is when I tap on back button, navigation becomes very slow. Any suggestion to solve this.

Tab bar with slide out menu

RearViewController.m
-(IBAction)unwindFromViewController:(UIStoryboardSegue *)segue
{
if ([segue.identifier isEqualToString:#"unwindToViewController"]) {
ViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:detail animated:YES completion:nil];
}
}
If I click back from my RearViewController the ViewController is not presented instead it just peeps and goes off(again shows RearViewcontroller).
Image2
I give you a solution for your question.
1.First remove triggered segue connection.
2.After that give push segue connection to Back to your required view controller.
3.Click Back Button Segue and give Identifier name as "goToMainViewController" or whatever you want just give there.Also segue should be "push".
Thank You

SWRevealViewController - push next view controller storyboard

I have a sidebar menu, made with SWRevealViewController.
I want to switch from the view controller and the view with the button to the next view controller. How I do that?
I try to used the ACTION SEGUE: "push", "modal", "revealview controller" and "revealview controller push controller".
But it doesn't works.
And I try it programmatically switch to the next viewcontroller.
MY CODE:
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationcontroller pushViewController:vc2 animated:YES]
This change the ViewController, but without the view (blackscreen).
It seems ViewController2 is a ViewController in storyboard. Try the below code:
ViewController2 * vc2 = [[self storyboard] instantiateViewControllerWithIdentifier:#"ViewControllerId"];
You should give Storyboard ID for ViewController2 as ViewControllerId in your storyboard.
Please note that your current ViewController should be in a Navigationcontroller stack to call self.navigationcontroller.

UITabBar disappears after pushed to new view controller

I have an UITabBarController that has 3 buttons. The second button points to ViewController1 which is connected to another view called ViewController2. After I tap a button in ViewController2 I programmatically present ViewController1 again, that works perfect except one thing. After I "arrived" to ViewController1 the tab bar disappears.
I'm using this method to navigate back to ViewController1. (exactly I navigate to its navigation controller, but already tried with the view)
- (void)presentViewControllerAnimated:(BOOL)animated {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"storyboard" bundle:nil];
UINavigationController *firstViewNavigationController = [storyboard instantiateViewControllerWithIdentifier:#"destination"];
[self presentViewController:firstViewNavigationController animated:animated completion:nil];
}
I call here the first method
- (void)didTapButton:(id)sender {
UIButton *button = (UIButton *)sender;
CGPoint pointInSuperview = [button.superview convertPoint:button.center toView:self.tableView];
[self presentViewControllerAnimated:YES];
}
This method hides the tab bar in the ViewController2, I already tried without it, therefore there is no problem with it.
-(BOOL)hidesBottomBarWhenPushed
{
return YES;
}
I can't figure out why this thing happens, I think it's a fair solution, that worked well for a several times when I needed to present views. I've read it can happen with segues, but I'm doing it with code without segues.
Actually your code works right. There should not be tab bar when you present FirstViewController from SecondViewController. Because when you call instantiateViewControllerWithIdentifier its basically creates a new instance of that view controller, and of course, there is no tab bar.
The right way to go back to your first view controller is to pop SecondViewController (or dismiss it, if it presented modally). So your final code should be like this
- (void)didTapButton:(id)sender {
// If this view controller (i.e. SecondViewController) was pushed, like in your case, then
[self.navigationController popViewControllerAnimated:YES];
// If this view controller was presented modally, then
// [self dismissViewControllerAnimated:YES completion:nil];
}
And of course, your view controller hierarchy in storyboard must be like this:
-- UINavigationController -> FirstViewController -> SecondViewController
|
->UITabBarController____|
-...
-...
I've tried the same and got the same result.
My solution was simple, on the push do this :
UINavigationController *firstViewNavigationController = [storyboard instantiateViewControllerWithIdentifier:#"destination"];
firstViewNavigationController.hidesBottomBarWhenPushed = true; // Insert this and set it to what you want to do
[self presentViewController:firstViewNavigationController animated:animated completion:nil];
and then remove your
-(BOOL)hidesBottomBarWhenPushed
{
return YES;
}

Pass String from UINavigationController to ViewController

I have three classes :
1.TyphoonViewController
2.WaterTableNaviController
3.WaterTableViewController
I am trying to pass a string from the first one to the last. But I only pass the string from the first to the second. It will be a black screen when I present the third ViewController.
I've tried to make the WaterTableViewController be the root of WaterTableNaviController in storyboard.
It did present screen, but the string wasn't passed.
From TyphoonViewController
- (IBAction)ParseBut:(id)sender {
WaterTableNaviViewController *vc = (WaterTableNaviViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"WaterTableNavi"];
[vc setUrl:#"My String"];
[self presentViewController:vc animated:YES completion:nil];
}
From WaterTableNaviController
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
WaterTableViewController* vc = (WaterTableViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"WaterTable"];
[vc setParseUrl:m_url];
[self.navigationController pushViewController:vc animated:YES];
}
The code you have in the navigation controller is wrong - if the WaterTableVC is the root view controller of the navigation controller, it's already been instantiated, so you shouldn't do it again. Also, you don't push to the root view controller. You don't need to subclass the navigation controller at all to do what you are trying to do here. You should make a modal segue from the button in TyphoonViewController to the navigation controller, and make WaterTableViewController the root view controller of that navigation controller. The button should not have any action method, because it triggers the segue directly. Instead, you should have the following code in prepareForSegue,
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UINavigationController *nav = segue.destinationViewController;
WaterTableViewController *waterTableVC = (WaterTableViewController *)nav.topViewController;
[waterTableVC setURL:#"My String"];
}
You can simply make another singleton class and put a property that can contain that string, so wherever you are, you can read that property

Resources