how to delete swipe up to back function - swift

when I use segue to go back in some part in my app this unnecessary function appear.
I try to cancel it by write
navigationItem.hidesBackButton = false
but it cancels only the navigation controller auto generated back button but it isn't cancel the auto generated swipe up go back function.

Related

SwiftUI: Execute code when back button for NavigationView is pressed

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.

How to Make an Instant Transition When Swiping on a Navigation View Controller

I have a navigation view controller set up, with a back button, to switch between 2 controllers. A user can either click the back button or just swipe on the screen to get the same behavior. What I'm trying to do is avoid a user that starts a left swipe, and then cancels the transition, staying on the same controller instead of going back to the first.
I know there is a way to block this transition, but this isn't recommended. What I am trying to do is have the transition instantly performed. I've seen on some apps where a user starts the left swipe, the swipe is immediately performed, and doesn't give them the option to cancel their transition halfway through. How do I perform this forced instant transition?
I'm assuming it has something to do with calling the interactivePopGestureRecognizer, but don't know what to do with it.
Thanks!
I figured out a way to do this. In viewDidDisappear, I added the following:
navigationController?.popViewController(animated: true)
If someone starts a swipe from the left, viewDidDisappear gets called. Even if he cancels the transition, the controller will still be popped forcing a return to the root controller.

How can I disable the user interaction for the Cancel button of my watchOS interface controller?

In my Apple Watch app, one of my interface controllers has a Cancel button at the top left corner. In my case, once a particular action is completed, I don't want the user to go back to the previous screen, so I want to disable the user interaction for that Cancel button. Even if I change the title to an empty string, user interaction still stays enabled.
We can't disable the back/cancel button user intaraction but can load controller without cancel button.
presentControllerWithName("NewInterfaceController", context: nil)
presentControllerWithName this will present controller with cancel button. If we use like below won't get the cancel button.
WKInterfaceController.reloadRootControllersWithNames(["NewInterfaceController"], contexts: ["NewInterfaceController"])
reloadRootControllersWithNames this will make our controller as a root controller so we won't get cancel button. This is how i resolved my issue. Hope it will help you as well.
NOTE: here [ ] is the syntax. exp: ["NewInterfaceController"]
You can't disable user interaction for back button.
But you can change a bit the way you present your views to accomplish what you want.
Start with your normal view. Check if you need to show the user the login. If you do, then present the login view Modally. At the end of login you close the modal view and you're back to normal view, without unnecessary back button.
This is simbesi.com's answer in watchOS 7/Swift 5.
Presenting the new controller modally:
presentController(withName: "NewInterfaceController", context: nil)
Presenting the new controller by replacing the root controller:
WKInterfaceController.reloadRootControllers(
withNamesAndContexts: [
(
name: "NewInterfaceController",
context: "NewInterfaceController" as AnyObject
)
]
)

How to Click/ Press Bar Button on Navigation Item programmatically

I have iPhone as below.
What I want is click Refresh button on clicking the Delete button ** programmatically**.
Note: I have provided tag also to Refresh button.
I assume u have delete and refresh actions say
-(IBAction)deleteAction:(id)sender
-(IBAction)refreshAction:(id)sender:
Now on delete action call refresh action simply like this:
-(IBAction)deleteAction:(id)sender
{
[self refreshAction:btnRefresh]; //provide refresh action along with refersh button
//I mean here act according to refresh method.
}

Where should I "save" changes in my iPhone view to 'create new' of an object?

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.