I have a NavBar, a TabBar and a SearchBar with a ScopeBar. So the user can perform a search via a remote server. Clicking on one TableRow of the TableView a new ViewController with a xib is pushed into.
It is doing some calculations and it is possible, that I have to dismiss this View(Controller) and I should go back like I am clicking the "back" button in the NavBar.
How could I do this programmatically and call a method in this ViewController, because I have to trigger the search with the saved search term.
Does anyone know this?
Thanks a lot in advance & Best Regards.
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
if you are
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
Use delegation. Have the table view controller create your new view controller newViewController and set newViewController.delegate = self before pushing it onto the navigation stack.
Then in newViewController, just before you popViewControllerAnimated: call some method like [delegate doWhateverWhenNewViewControllerIsPopped: ...]. Ideally you declare a protocol called something like NewViewControllerDelegate and have the controller above implement it.
You can change the back button of NewViewController to something like "Done" or whatever by changing it's left navigation button. (See the properties of UIViewController.)
Hope that makes sense.
I solved the problem, take a look at the comments.
Related
The UINavbarcontroller will go back to the previous VC when i press the Left button on the NavBar. Works as expected.
I also need to force the screen to go back from another button, so was wondering is there something i can call to make this happen? I dnt see any method attached to UINavbarController docs for this.
try popViewController:
[self.navigationController popViewControllerAnimated:YES];
Try looking at the UINavigationController docs instead, it's the fourth of 8 instance methods:
popViewControllerAnimated:
Pops the top view controller from the navigation stack and updates the
display.
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
I have looked everywhere for this.
I have a navigation controller. I like using the navigation controller with all the animation however the bar irritates me so i have disabled it.
I would like to create a UIButton that will push the navigation controller back a page instead.
Is this possible? can someone tell me how to achieve this and get hold of the correct item that allows to push back to the previous view.
Thanks
Create a button with a target on a function that do:
[self.navigationController popViewControllerAnimated:YES]
Since navigation controller works as a stack your current view controller is poped out from the stack and the previous view controller is showed
Look at the UINavigationController documentation, you can have your UIButton call the navigation controller's popViewControllerAnimated:
Did you try these methods in the UINavigationController class:
– pushViewController:animated:
– popViewControllerAnimated:
– popToRootViewControllerAnimated:
– popToViewController:animate
Call the pop methods from your button's action method.
Assuming you have a valid reference to the Nav Controller, set up the button action to use:
Pops view controllers until the specified view controller is at the top of the navigation stack.
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
i'm working in view-based template,
and I have main.m, which I haven't touched.
and one view controller which is my current display,
and one dummy controller which has nothing.
If I implement the dummy controller, and want to switch between
two view controllers, where and how should I do it?
I've only worked with subviews,
but not quite sure where to touch the view controllers...
does it work the same as addView, release as with subviews?
Please help me out..
It depends on how you want you're looking to do. You could present your dummy view controller either modally or non-modally. To do it modally, check out:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
Here is a sample on how you would do something like that:
DummyViewController *dummyController = [[DummyViewController alloc] init];
[self presentModalViewController: dummyController];
You could also do something like:
- (void)presentFlipSideViewController:(UIViewController *)flipsideViewController
You would call these methods when the user did something, such as tap a button. Both of these methods would be implemented in the view controller handling the tap or action, in your case, the project template view controller .
I am using a UINavigationController to slide from a UITableViewController to another view. In that second view I have created a custom "Back" button which is attached to an action.
What code do I use to return to dismiss the current view and slide back to my first view? I need something that is the equivalent to [super dismissModalViewControllerAnimated:true]; but obviously this is not a modal view.
Thanks.
Look at one of the following three methods on your navigation controller:
popViewControllerAnimated:
popToRootViewControllerAnimated:
popToViewController:animated:
Depending on how you want to handle it of course. Generally one just uses the first method to go back to the last view (the one that pushed your current view onto the navigation stack).
Use popToRootViewControllerAnimated method in UINavigationController:
[self.navigationController popToRootViewControllerAnimated:animated];
I am using Tab bar + navigation based application and I have 4 tab bars. When I navigate from one view controller to another view controller, the viewWillAppear: method doesn't seem to respond and I am being forced to call it manually by creating the object of the next view controller. So my question is, how do I avoid calling the viewWillAppear: method manually whenever I navigate from one view controller to another? Instead, it should get triggered automatically just like the viewdidLoad: method gets triggered when you navigate from one view controller to other. Please guide me on how could I do that.
Hoping for the best possible Answer
Thanks in Advance
You are correct, viewWillAppear is a little special, it is usually called automatically but in some cases including when you are adding a view controllers view manually (view addSubview:), and also when adding this as a view controller to a UITabBarController or UINavigationCnotroller (of which you have both !) it doesn't get messaged.
This however is only for the root view, as you navigate (maybe with a navigation controller) back and forth, that root view's viewWillAppear will get triggered as some point.
In short, if you need to implement something in viewWillAppear in these cases, you should message it yourself when you know it's going to be presented. You can handle this case in your view controller, check out the following article about the matter:
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
Good luck.
You should check UITabBarDelegate then look for the method:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item.
Description: Sent to the delegate when the user selects a tab bar
item.
In some apps that have a tab bar controller, each tab also needs a nav controller before a view can be added:
[[[_mainTabController topViewController] navigationController] pushViewController:renewalScreen animated:YES];
Do you mean 4 tab items on a tab bar, rather than '4 tab bars'? If you have a tab bar with tab items, the viewWillAppear: methods absolutely should be called by the system as the tabs are selected by the user. You could have other issues that are causing the problem.
You didn't forget to call [super viewWillAppear] somewhere?
Try using the viewDidAppear method instead.