I create a UINavigationController (as a initial screen) and connect them with my UITableViewController (as a root).
Next, I create another UINavigationController and connect with my UIViewController. Inside my UITableViewController I connect my first cell with UINavigationController (That was connected with my UIViewController) (Segue -> show).
When I run the project my table appears, when I select my first row, my UIViewController appears. Thats great!
When I was in my UIViewController the back bar button doesn't appears, in my case I create a left bar button, that will run a function to dismiss that view and go back to my UITableViewController, for that I use many codes:
-(void)back{
NSLog(#"Called");
[self.parentViewController.navigationController popViewControllerAnimated:YES];
}
-(void)back{
NSLog(#"Called");
[self.navigationController popViewControllerAnimated:YES];
}
-(void)back{
NSLog(#"Called");
[self.navigationController popViewControllerAnimated:YES];
}
But all of they doesn't works and my view don't dismiss, how can I solve this problem?
The problem is that your navigation controller, that you call from your table view cell, has only a single view controller (yours) on its navigation stack. So it cannot pop anything from this stack, else the stack were empty.
What you have to do instead is to dismiss the navigation controller itself.
I think that the solution would be to remove the second navigation controller. Since the TableView is already embedded inside a Navigation Controller, the show segue to the UIViewController must be directly connected to it.
Related
I have the next structure:
* TabBarController
- ViewController with TableView
- ViewController
When I select any row on the TableView, the segue forwards me to the ViewController. On the ViewController with the TableView, I see the BottomBar, but after the segue it disappears.
How can I keep it on my ViewController? I've even putted the last ViewController in NavigationController, but it did not help me, too.
How can I fix it?
Your hierarchy should look like this:
* TabBarController
- NavigationController
- ViewController with TableView
- ViewController
Using a Show segue with an UINavigationController pushes the destination view controller onto the navigation stack. However, most other view controllers present the view modally (i.e. by sliding over the source view controller) with Show, which is why your tabbar disappears.
uncheck hide bottom bar when pushed from your view controller in story board
I am working on a new project of mine and am looking for what the best solution to keep the UITabBarController displaying even when using a segue to push to a UIViewController.
Currently I have an Initiation of our UITabBarController on app launch, which contains multiple viewcontroller relationships. Particularly the initial view controller option is a custom UIViewController which implements a UITableView. Once a cell is selected I call a show(push) segue to another UIViewController. This is where I lose my TabBar which is as expected. Now I have tried different approaches such as setting the hidden value of our tabbar to YES, but does not seem to help.
Code
When Cell Selected:
[self performSegueWithIdentifier: #"tableCellOptions" sender: self];
When preparing for segue:
if([segue.identifier isEqualToString:#"tableCellOptions"]) {
additionUITableView *move = (additionUITableView *) segue.destinationViewController;
move.thisOption = [menuOptions objectAtIndex:cellPushed];
}
What would your approach be to this and why?
If you have Tab bar controller as the initial View Controller, the tab bar will show by default on each view controller.
If you are using storyboard or xib file, then select the tab bar item in view controller and check its properties, and make sure "hide tab bar on push" is unchecked.
Programmatically you can do this,
self.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:viewControllerToPush animated:YES];
Place it in viewDidLoad or viewDidAppear.
I hope this solves your problem.
In a UITabBar based application, UIImagePickerController is opened ,after dismissing it UIViewController loads earlier than UITabBar and as a result whole content of UIViewController is not being shown?
I guess after dismissing controller method for navigation would be an issue.
Check if you use below method:
[self.navigationController popToRootViewControllerAnimated:YES];
Then it will navigate flow to root controller.
So replace this method with
[self.navigationController popViewControllerAnimated:YES];
Above method pop back to previous controller.
I have a view controller. When I press a button in it, a popover controller with a uitableview shows up. I select a row, which shows another view with some controls in it. When I press a button that says "Save Item", I want it to dismiss the popover. How do I do this?
Here's what I've tried:
Using the delegate and protocol pattern. This hasn't worked since in order to push another view inside my tableview, the whole thing must be embedded in a navigation view controller, so when I segue, it segues to a nav controller, not the tableview which I could set the popover delegate for.
Adding my main view as a member of the view I want to dismiss from. I don't know why this doesn't work.
The Hard Clean Way
There are four view controllers in the story, plus a popover controller. I will call the three view controllers "main view controller", "nav", "vcA", and "vcB". As I understand it, "nav" is the initial content view controller of the popover and has "vcA" as its root view controller.
main view controller -> popover controller -> nav -> vcA -> (later) vcB
When you present the popover from your main view controller, you keep a reference to the popover controller. This is what makes dismissing possible, as you know.
When you create the Save button, you make its target the main view controller and its action a method in the main view controller. You will have to set this up in code; it cannot be configured from a storyboard because you cannot form an action from one scene to another. (You are able to do this because you started out with a reference to nav and vcA when you configured the popover controller initially. Thus you can hand vcA a reference to self, the main view controller. If necessary, you can then pass this reference down the chain from vcA to vcB as vcB is summoned and pushed onto the navigation stack.)
Now the user taps Save, your main view controller's method runs, and it uses its reference to the popover controller to tell it to dismiss.
The Easy Dirty Way
The heck with all that. The main view controller registers for an NSNotification. The Save button posts that NSNotification. Done. :)
The Middle Way
You could set the whole chain up in your storyboard using a popover segue, and do the dismissal through an Unwind segue matched by an unwind method back in the main view controller. I never think of this initially, because I don't like popover segues very much. But it does work.
This is how I solved my problem (sorry for the bad english):
First, Create a property of UIStoryboardPopoverSegue in the VcA and set it from the main view controller.
Nav -> VcA_ViewController
#property (strong, nonatomic) UIStoryboardPopoverSegue *popupSegue;
Then, in the Main View Controller prepareForSegue set the property:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"your segue from the mainview to the navigation"]) {
UINavigationController *navigationController = (UINavigationController *)c;
VcA_ViewController *vcA = (VRPointOfInterestsFiltersViewController *) navigationController.topViewController;
vcA.popupSegue = (UIStoryboardPopoverSegue*)segue;
} }
Now, from the VcA controller you can have the dismiss button
- (IBAction)dismissPopoup:(id)sender {
[self.popupSegue.popoverController dismissPopoverAnimated:YES]; }
Don't forget to link the popOverSegue from the MainViewController to the NavController.
Hope it helps!
There are two views in a tabbarviewcontroller. And the first tab has its view controller called myViewController which contain its IBOutlet. Pressing the button on the first view will present a view controller. After dismissing the view and back to the tab, the viewWillAppear of myViewController won't be called,but viewWillAppear of tabbarviewcontroller will. I need to reload the information on the first tab. If I use viewWillAppear in tabbarviewcontraller, how do I change the values of these property in myViewController? If anyone has idea ? Thanks.
If you want to call viewWillAppear of the viewController, you can add this to viewWillAppear of the TabBar
for (UIViewController *viewController in tabBarController.viewControllers)
{
[viewController viewWillAppear:YES]
}