Understanding the executeSegueWithIdentifier Function

Can anyone be more knowledgeable than I explain performSegueWithIdentifier:sender: for me? I need to switch views (and classes), as well as transfer multiple NSStrings and IDs to this view class. I was wondering if this is possible with performSegueWithIdentifier:sender:

Thank!

+50
ios objective-c uikit xcode segue
Feb 07 2018-12-12T00:
source share
4 answers

You must first configure segue in your storyboard and assign it the appropriate identifier . (Click on the segment (left pane), then click β€œAttributes” (right pane).

You can then associate this with buttons or select table rows from a storyboard, or you can call it in code using performSegueWithIdentifier:sender:

After that, prepareForSegue:sender: will be sent to your controller. You override this method in a subclass of the view controller and you can configure the target view controller as follows:

 TargetViewController *targetVC = (TargetViewController*)segue.destinationViewController; targetVC.string1 = string1; 

And so on. sender in this method will be the object that you use as sender in the original method call.

+77
Feb 07 2018-12-12T00:
source share

Most sessions are automatically initiated as a result of user interaction. For example, if you have a segue that translates from one button to the scene in the storyboard, when you click the button, the segue starts automatically.

Sometimes it makes sense to run a segue program call β€” for example, you have a high-performance scene that displays when a user wins a game round. It is impossible to express the concept of winning in the storyboard itself, so instead you can create a segue, assign it an identifier and call -performSegueWithIdentifier:sender: at run time.

Another segue-related method in the UIViewController, -prepareForSegue:sender: is a method that you must override to perform any configuration on the destination view controller.

+9
Feb 07 '12 at 17:27
source share

In prepareForSegue:sender: you get the opportunity to configure destinationViewController : where you pass it the data it needs. It was discussed at Cocoa Competency App for iOS .

+3
Feb 07 2018-12-12T00:
source share

Today I ran into the issue of performSegueWithIdentifier: it didn’t execute due to not setting the delegate queue in the URL session.

So check to see if you really set up the delegate queue when creating the URLSession, otherwise the URLSession will create it.

 urlSession = [NSURLSession sessionWithConfiguration:sessionConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]]; 

I mention this here because quite often I see that URLSession processing ends up invoking some kind of user-interface activity. And performSegue should be executed on the main, otherwise it will not do anything.

-one
Nov 11 '14 at 14:19
source share



All Articles