Pop the Current View Using Segues/Storyboard on iOS 5

Pop the current view using Segues/Storyboard on iOS 5

You could try calling [self dismissViewControllerAnimated:YES completion:nil]; from the controller you want to dismiss (whether the controller has been pushed, or shown modally).

Here is the related documentation : UIViewController Class Reference

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

Why don't some of my push storyboard segues show an option for peek and pop?

sorry about the late Reply. I was having the same problem. it seems like by design Apple only show the peek&pop option in interface builder for Action segues (like segues from buttons or cells to a UIViewController) but NOT for Manual segues (i.e segues from ViewController to ViewController, that we usually trigger by code and set-up in prepareForSegue: ). This is mentioned here

Why does View Controller Shift in Storyboard on Button Segue

You need to set fullscreen style manually if select model style,
a fullscreen option did not show in Push type, you must use Navigation Controller if you want to set fullscreen for Push
https://i.stack.imgur.com/rg20Y.png

Swift IOS keep view controller running in background after pop

A popped view controller does not "stop running". It is returned to you, and if you don't retain it, it is completely destroyed.

If you don't want that to happen, retain it when it is returned. You are currently ignoring the returned view controller:

 self.navigationController?.popViewControllerAnimated(true)

Instead, keep a reference to it:

self.mySecondViewController = 
self.navigationController?.popViewControllerAnimated(true)

Be warned, however, that this is a very unusual architecture. You will not be able to use the storyboard segue to push again, because it will push a different copy. It would be better to abandon your navigation controller architecture entirely, as it is completely unsuited to the idea of a view controller persisting after it is popped. If you want an architecture where two view controllers persist simultaneously, you would be better off using a UITabBarController — or, even better, reorganize your app completely. The notion that you need the view controller to persist after being popped is a "bad smell": it means that you have put the functionality in the wrong place. Put the functionality in a place that does persist, rather than forcing the view controller to persist in some artificial way.

IOS 5 SDK and Segues

You could try using the navigation controller to pop back. This will probably produce the effect you are after.

[self.navigationController popViewControllerAnimated:YES];

Storyboard: inferring navigation bar after changing segues

As suggested by JoePasq, "Have your view controller class the root view controller of the navigation controller". Select your view controller which you want to set as Root screen and goto Editor/EmbedIn option and select navigation controller. You will get a navigation-controller embedded with your root view controller. Instead of setting up segues you can change your screens programmatically in your program. In your method for button click event write a similar code as below;

- (IBAction)okPressed:(id)sender {
UIStoryBoard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; //MainStoryboard is the name of your storyboard
SecondViewController *secondView = [storyboard instantiateViewControllerWithIdentifier:@"sView"];
//sView is the identifier name set by the user, (present inside Attribute Inspector - View Controller)
[self.navigationController pushViewController:secondView animated:YES];

Let me know if this works or there is also another way to do it.

Segues and clearing historical ViewControllers from memory

When you are using segues the flow moves backwards and forwards. When the user moves backwards (ie presses "back") then it will not push to a new VC but it will pop to a VC that already existed. When you pop, the current VC is removed from the stack and memory.

If you have segues to move backwards in the flow then this is wrong. You only need segues to move forward.

A PROPER PREPARE FOR SEGUE

In prepare for segue you should never create your own view controllers and push to them. The storyboard is there to do all of this for you.

A proper prepareForSegue method should look something like this...

- (void)prepareForSegue:(UIStoryBoardSegue*)segue
{
if([segue.identifier isEqualToString:"SomeSegue"])
{
MyNewViewController *controller = segue.destinationViewController;

controller.someProperty = "some value to pass in";
}
}

That is all you need. Note that you only need this if you intend to pass some information to the new view controller. If you are not passing anything forward then you don't need this method at all.

When the method ends the new VC will get pushed onto the screen by the storyboard file.

UNWIND SEGUES

If you have a random flow (like in your comment) then you can use unwind segues to achieve this.

In you 'A' view controller have a function like...

- (IBAction)someUnwindAction:(UIStoryboardSegue*)sender
{
//some action to run when unwinding.
}

It needs to receive a UIStoryboardSegue object. If set up as an IBAction you can also access it from Interface Builder.

Now when you want to go A > B > C > B > A then just used the standard push and pop (from the segue and back button).

When you want to go A > B > C > A then you can use the unwind segue from controller C.

If you have a cancel button or something in controller C and this is in the Interface Builder and this should take you back to controller A. Then in the Interface Builder underneath controller C you will have a little green square with a door and an arrow pointing out of it. Just point the action of the cancel button to this symbol and choose "someUnwindAction". (Note, unwindAction is in A, button is in C.) XCode then uses this to pop you all the way back to A and deals with removing any memory and stuff. If you want you can send additional information back to A too.

If you want to access this unwind segue from C programmatically then you can run...

[self performSegueWithIdentifier:"someUnwindAction" sender:nil];

This will also pop back to A.



Related Topics



Leave a reply



Submit