0

I am a beginner in iOS development. I have a problem when I move the screen. I clicked the button on the story board, then drag it with the right mouse, and then clicked on the view controller that I wanted to move. However, the navigation back button is not visible when the button is pressed. What's the reason?

Main.storyboard

storyboard

storyboard

Cell phone

enter image description here

Move when the lower right yellow button is pressed.

Move when the lower right yellow button is pressed. My right button is not 'Bar Button Item' but just a button. The reason is that 'Bar Button' is not what I want.

************************ Edited Start ************************************ story

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "goAgreeScreen" { performSegue(withIdentifier: "goAgreeScreen", sender: self) // get Error } else if segue.identifier == "otherScreen" { } } 

Error is Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee5677ff8)

************************ Edited end ************************************

*******************Edited Two ******************************************* my board

Move Main Screen Button

 @IBAction func Onclick(_ sender: Any) { AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in if response { print(response , ": granted") let center = UNUserNotificationCenter.current() // Request permission to display alerts and play sounds. center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in if granted { print(granted, ": is granted") DispatchQueue.main.async { self.moveScreen()} } else { print(granted, ": is not granted") DispatchQueue.main.async { self.moveScreen()} } } } else { print(response , ": not granted") let center = UNUserNotificationCenter.current() // Request permission to display alerts and play sounds. center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in if error == nil { if granted == true { print(granted, ": is granted") DispatchQueue.main.async { self.moveScreen()} } else { print(granted, ": is not granted") DispatchQueue.main.async { self.moveScreen()} } } else { print(error as Any) } } } } } 

*******************Edited Two end *****************************************

15
  • Did you see the "Main" heading on your cellphone when you were on the screen with the yellow button? If not, it's possible that you accessed the viewController without it being embedded in the navigationController Commented Sep 5, 2019 at 9:51
  • Yes. I can't even see Maine. What do you mean adding it to the navigation controller? How can I add it? Commented Sep 6, 2019 at 1:12
  • Depends on how you are showing the first page. If you are doing it via storyboards, click on the navigation controller and tick "Is initial view controller", and an arrow will appear beside the nav controller. Then when you open the app it should be inside the navigation controller and you will see the "Main" heading and the back button. Commented Sep 6, 2019 at 2:31
  • @Daniel As you can see from the pictures on my storyboard, it's connected to the screen Could you look at my edited question? Commented Sep 6, 2019 at 2:45
  • Ansersion's answer below is a good reference; if you review that you'll see what needs to be done. You shouldn't put the performSegue command inside the prepare(for segue) function, that's probably what's causing the error (and you don't need to performSegue if you're using storyboards). Also not quite sure what you mean by "it's connected to the screen"? Commented Sep 6, 2019 at 3:23

2 Answers 2

1

Are you presenting the ViewController programmatically? It seems that the navigation bar is not shown. Maybe you have to present if in a IBAction. Create it connecting a button. Set the identifier to the segue (on the Storyboard) and call it with:

performSegue(withIdentifier: "myIdentifier", sender: self) 
Sign up to request clarification or add additional context in comments.

1 Comment

Do you mean you have to do an event when you press the button?
1

I think that you don't need any code for your situation. Here is a Quick-Start example from Apple which is very clear. https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementNavigation.html#//apple_ref/doc/uid/TP40015214-CH16-SW1

2 Comments

As you can see from the pictures on my storyboard, it's connected to the screen
But I don't see the Main title, I don't see the Back button.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.