I have MainView, which has a navigationLink to EditProfileView.
When I press the back button on EditProfileView, I want some code to execute that updates a database.
I would use onDisappear(), but the issue is that EditProfileView has another view ImagePickerView presented as a sheet come up, and having that view come up triggers onDisappear().
In other words, I want my database code to execute only when we press the back button to go from EditProfileView back to MainView.
Is there a way to do this?
Add your own back button to replace the native one as the left button. Then programmatically dismiss your view.
Related
I want to navigate from a splash/login view to a home view without the possibility of going back unless the user restarts the application using SwiftUI. I know I can use a navigation link and SwiftUI will present a back button. Is there a way to go from view to view without the back button?
If you need to present a view, you can look at this article
On the contrary if the concern is not to show the back button, on the home view one can hide the back button using the configuration like
.navigationBarBackButtonHidden(true)
I have a navigation bar in my app. The below pictures are in the order of navigation.
Problem I have is, on clicking the "Main" button , I am able to perform the action and goto the required screen , but the navigation bar does not look like the first on (with Menu as left button). Instead it look like 4th image. How to make it look like first image so that I can make the user to navigate to "Menu" screen by clicking menu button ?. Thanks for the help …!!!
If I'm understanding this correctly, you may have pushed the first view controller (The one from screenshot 1) when clicking on main which is why you see "lens" in the back button. That back button takes the title of the previous view controller in the stack. What you want to do is pop to the first view controller when they click on Main using either popToRootViewController or popToViewController:animated
I'm looking for some kind of solution to a problem I have.
I have a main view controller. On this view controller I have a button it works well most of the time. But when i pop up smaller view controller onto my main view controller, a part of the small view controller is behind the button.
So the button is is still on the front of the sceen, with the small view controller behind it.
The small view controller seems to take the key presses that were ment for the button. Is there a way to get the button to take the keypresses? I though it having the higher z order would make this so, but obviously not. Is there a work around of this?
Or am I going to need to have an invisible button on my small view controller that calls back to the parent view controller to say the button was pressed.
Many Thanks
C :)
Key presses go to the first responder of a window not the frontmost view in the z order. So after popping up the small view controller make the button first responder then key presses will go to it.
I have a view that creates a new core data managed object, and fills in all the required properties and also allows optional ones. I originally had a "Done" button on the top left, and when that was pressed, I validated the object then saved and removed the view.
Now I have an edit/done type setup on the top right, so sometimes there are two identical "Done" buttons on the top of the view. I want to switch the left side button so that it just has the normal "Back" button, then somehow validate and stop the view from being removed if it doesn't validate. I can't find any way to capture the method called by that back button and modify it, and viewWillDisappear doesn't work cause there's no way to abort the disappearing.
How can I make this work? I need to validate this, then save, then remove the view if validate and save worked only.
It sounds like your view is a perfect candidate to be pushed modally instead of through the navigation controller stack.
Push the view that creates your NSManagedObject modally:
[self presentModalViewController:yourViewController animated:YES]
Then continue to use your top right EDIT/DONE button for editing/validation as you currently are and when validation is successful simply save your object and dismiss the modal view controller from the parent view controller:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
For more details check http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
If you still want to use a button on the left hand side perhaps you can change the right button to say EDIT/CANCEL and add a DONE button on the left side that is only visible when you're not in EDIT mode. If appropriate you can point the DONE button to run through the same validation process before dismissing the modal view using the code above but it probably makes sense that the EDIT/CANCEL button takes care of it.
I hope this helps.
Rog
There is no documented way to intercept the standard back button of UINavigationController. If you want this functionality, your only option would be to customize leftBarButtonItem with a custom button.
When the user taps that button, you can first validate your object and then call popViewControllerAnimated:.
It's hard to mimic the look of the built-in back button, though.
I have added add(+ symbol button) button to my navigation controller.
When I click it a view appears from bottom. I added a navigation bar and two buttons to it.
One save and one cancel button. And the view have one textEdit box. After editing I can save or cancel. If I touch cancel I need the view to disappear like it should go down again.
I think all iPhone , iPodTouch users use it. Like when they touch Add item then a view appears from bottom and when they cancel it goes down again. How can I make in this way in my application.
Maybe you're talking about a UIActionSheet?!?
http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html