0

I have a view in which a user selects an action to take and on that next screen there is a save and a back button. For both of the buttons the last line is dismissViewControllerAnimated:.

I need a way to make the 1st screen show only if the back button is used. save should send back to the main screen/rootViewController I am fairly new to iOS but not programming in general and just need a nudge in the right direction.

Could I set a bool flag to show or not? Maybe I can set the Tag on the view and then check that in the other screens on save/back? I assume I can check the parent view.

Sorry if this is a dup but I cant find anything specifically for this.

EDIT: I am not using a nav controller and am showing the views modally.

John S
  • 573
  • 8
  • 22
  • 2
    What is the structure of your view controllers? – Wain Jul 22 '13 at 17:10
  • Are you using a Navigation Controller or presenting views modally? – Sam Spencer Jul 22 '13 at 17:11
  • @RazorSharp @Wain All the views are modal I believe. At least that is how I am doing it in this set of screens. I just took over this project from a third party and it is my first time working in obj-c. All the viewcontrollers are called like this `[self presentViewController:myController Animated:YES Completion:NULL];` I am not using a nav controller anywhere. – John S Jul 22 '13 at 17:17

3 Answers3

1

The answer will vary depending on how your UIViewControllers are structured and setup. If you're using a then you can POP to the root view controller using:

[self.navigationController popViewControllerAnimated:YES];

If you're presenting your UIViewControllers modally, you can try to dismiss the presenting View Controllers of your modal view controller using the presentingViewController property:

[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];

You may also want to take a look at Unwind Segues if you're using a Storyboard:

Finally, as far as determining whether the back button is pressed or another button - that depends on how the app is setup. You'll need to use your own logic (probably if / then statements or case / switch) to determine which button was pressed. You also may want to check out the sender argument in IBActions.

Community
  • 1
  • 1
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
  • I have removed all subviews and it sends me back to the first screen. This view is not actually the first in the stack but the first the user would see after choosing the image or taking a new one. Is it possible that the camera sets itself as the root view controller or super and that is why it is sending me to that screen? EDIT: On the real first screen the user clicks a camera button and it opens the camera then sends them to a screen to preview the image and choose an action to take with it. – John S Jul 22 '13 at 20:20
  • @JohnS Hmm... I don't fully understand what you're saying here. Maybe you could edit your question and provide more details? Or are you using the standard system `UIImagePicker` to display the camera and it's editing features? – Sam Spencer Jul 23 '13 at 02:15
  • Thanks for your help. See my answer for the solution. I was confused on the terminology and that didnt help. – John S Jul 24 '13 at 20:54
0

John, to have a UINavigationViewController return to it's root viewcontroller, you use:
[nameOfNavController popToRootViewControllerAnimated:YES];

The other guys are correct that the information you've provided is definitely not enough to determine exactly what you need to do.

You can use the presentingViewController property of a modal view controller to access it's presenting controller.

james_womack
  • 10,028
  • 6
  • 55
  • 74
0

It turns out that I was using the terminology wrong. I am presenting all views modally and that is the issue, there is no navigation controller. I ended up using NSNotification to build a listener and had the main view controller listen and then dismiss the view and hence show itself. Worked a treat.

here is the link to the code I ended up with. http://iphonedevsdk.com/discussion/114737/view-heirarchy-issues-possibly-from-the-camera

Hopefully this helps someone else.

John S
  • 573
  • 8
  • 22