Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 501 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Swift - How to hide back button in navigation item?

#1
Right now I have two view controllers. My problem is I don't know how to hide the back button after transitioning to the second view controller. Most references that I found are in Objective-C. How do I code it in Swift?

Hide back button code in Objective-C

[self.navigationItem setHidesBackButton:YES animated:YES];
Reply

#2
Try with below code in **viewWillAppear** method.

> self.navigationItem.setHidesBackButton(true, animated: true)



Read below link for more support.

[To see links please register here]


Reply

#3
put the below code in `viewWillAppear` method.

navigationItem.hidesBackButton = true
Reply

#4
In SwiftUI

```swift
.navigationBarBackButtonHidden(true)
```
Reply

#5
```swift
self.navigationItem.setHidesBackButton(true, animated: false)
```
Reply

#6
According to the [documentation](

[To see links please register here]

) for `UINavigationItem` :

self.navigationItem.setHidesBackButton(true, animated: true)
Reply

#7
In case you're using a `UITabBarController`:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.navigationItem.hidesBackButton = true
}
Reply

#8
Put it in the `viewDidLoad` method
```
navigationItem.hidesBackButton = true
```
Reply

#9
That worked for me in Swift 5 like a charm,
just add it to your viewDidLoad()

self.navigationItem.setHidesBackButton(true, animated: true)
Reply

#10
Here is a version of the answer in <h2>Swift 5</h2> that you can use it from the storyboard:


```swift
// MARK: - Hiding Back Button

extension UINavigationItem {

/// A Boolean value that determines whether the back button is hidden.
///
/// When set to `true`, the back button is hidden when this navigation item
/// is the top item. This is true regardless of the value in the
/// `leftItemsSupplementBackButton` property. When set to `false`, the back button
/// is shown if it is still present. (It can be replaced by values in either
/// the `leftBarButtonItem` or `leftBarButtonItems` properties.) The default value is `false`.
@IBInspectable var hideBackButton: Bool {
get { hidesBackButton }
set { hidesBackButton = newValue }
}
}
```

Every navigation item of a view controller will have this new property in the top section of attributes inspector
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through