I need to execute an action (emptying an array), when the back button of a UINavigationController
is pressed, while the button still causes the previous ViewController
on the stack to appear. How could I accomplish this using swift?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
As I understand you want to empty your
array
as you press your back button and pop to your previousViewController let
yourArray
which you loaded on this screen isReplacing the button to a custom one as suggested on another answer is possibly not a great idea as you will lose the default behavior and style.
One other option you have is to implement the viewWillDisappear method on the View Controller and check for a property named isMovingFromParentViewController. If that property is true, it means the View Controller is disappearing because it's being removed (popped).
Should look something like:
Try this .
Try on this too.
If you are using
navigationController
then add theUINavigationControllerDelegate
protocol to class and add the delegate method as follows:This method is called whenever the navigation controller will slide to a new screen. If the back button was pressed, the new view controller is
ViewController
itself.It's not difficult as we thing. Just create a frame for UIButton with clear background color, assign action for the button and place over the navigationbar back button. And finally remove the button after use.
Here is the Swift 3 sample code done with UIImage instead of UIButton
write the code need to be executed
Remove the subView after action is performed