back button navigation very slow - ios

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.

Related

tabbar is not displaying in secondview controller

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];
}
}

How do i handle navigation Back button view hierarchy?

Here is the problem
1) Rootview controller - MYAssetVC-> Embedded with NavigationController here pushing for button to another Addfilevc.
2) Addfilevc Has dropdownTextfield It will push to another vc have tableview selected row will display in the textfield.
3)if i select another value from the dropdown textfield it will push to the vc again there i will select.
Navigation bar back button will navigate to all my view hierarchy i want to handle this one. if i go to same view it should navigate back only once that to the recent visit how to do this.
As i am new to iOS. give any suggestion.
Navigation from 1->2->3
navigation backbtn 3->2->1
if i navigate like this 1->2->3-> backbutton 3->2 again 2->3 backbutton 3->2 again 2->3
IF i navigate now using back it is displaying all my route path it should navigate like 1->2->3> and 3->2->1 if any number of times i perform actions in 2 & 3.
1,2,3 are view controllers.
Create an IBAction for the back button and use popViewController.
[self.navigationController popViewControllerAnimated:YES];
This will help you to go back one page. You have to write this in all the pages where there is a back button and you want to go back one page.
If you want to go back directly to rootViewController, try this:
[self.navigationController popToRootViewControllerAnimated:YES];
And if you want to pop to any specific viewController in the stack, you run a for loop to find the viewController you want to navigate to and then simply popToViewController, like this:
for (UIViewController *viewController in self.navigationController.viewControllers) {
if ([viewController isKindOfClass:[Addfilevc class]]) {
[self.navigationController popToViewController:viewController animated:YES];
}
}
Hope this helps to clear your concept.
EDIT
In swift:
The [self.navigationController popViewControllerAnimated:YES]; will become self.navigationController?.popViewControllerAnimated(true)
The [self.navigationController popToRootViewControllerAnimated:YES]; will become navigationController?.popToRootViewControllerAnimated(true)
And the for loop will be as below:
You can use this if you are using storyboard
let switchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("view2") as ComposeViewController
self.navigationController?.pushViewController(switchViewController, animated: true)
And the for-in loop
if let viewControllers = self.navigationController?.viewControllers {
for viewController in viewControllers {
self.navigationController!.popToViewController(viewController, animated: true);
}
}
Thanks.

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;
}

Push ViewController in NavigationController from side menu

I'm using a UINavigationController and I have a side menu in it. The problem is that when I want to push a UIViewController in the NavigationController from the side view it doesn't work. To do it, is use that code:
[self.slidingViewController resetTopView];
CDRecentChats* recentchats = [[CDRecentChats alloc]init];
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"conversation"];
[recentchats.navigationController pushViewController:controller animated:YES];
As you can see, I first close de side menu and then call the NavigationController to push a new ViewController. Using that code, the only thing that happens is that the menu is closed, but the NavigationController doesnnt push any ViewController. what can I do?
popToViewController means to go back to one that has already been made part of the navigation controller's stack. If you're trying to show a new one, use pushViewController.

Custom button push back

I have two views which use UINavigationController. I want the second view to "slide" with animation back to the first view when I tap on a custom button. (not the original in navigationbar)
Try something like this on that button action,
[self.navigationController popToViewController:aViewController animated:YES];
or
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] - 2)] animated:YES];
Here aViewController represents the previous view controller. Similarly you can pop to any viewcontroller you want by using a similar code.
[self.navigationController popToRootViewControllerAnimated:YES]; will take you to the root view controller.

Resources