Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard - setting delegates

Tags:

Before storyboards I was able to set delegates and datasources just by dragging an outlet to a class. With storyboards, I cannot drag the outlet to another view controller; there is no destination that will respond to it.

If I click on a view controller object, I am able to see the class owner at the bottom, but as soon as I select the other view controller containing the outlet, the old selection is gone, so I cannot connect the two.

Is this Apple's way of saying we should only connect them programmatically?

like image 973
Morrowless Avatar asked Jan 24 '12 04:01

Morrowless


People also ask

How do I add a delegate to a storyboard?

The menu will show a list of properties (including the delegate property) for that object. Then simply right click on the delegate property, hold it, and drag it (a blue line will appear) and link it to the object's delegate.

What are delegates in iOS?

What is delegate methods in iOS? It is an easy and influential pattern in which one object in a program works on behalf of or in coordination with, another object. The delegating object keeps a reference to the other object and at the suitable time sends a message to it.

Can we use multiple storyboards in one application?

An app's storyboard can be easily divided into multiple storyboards, with each one representing an individual story. Best example will be Pre-Login flow. Splash Screen, Login, Signup, Forgot Password, T&C etc can be easily seen as a separate flow independent of the functionalities in the app.


1 Answers

Correct. Set the delegate or other data in your prepareForSegue:sender: method. Here is an example:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {     // Check the segue identifier     if ([segue.identifier isEqualToString:@"showDetail"])     {         // Get a reference to your custom view controller         CustomViewController *customViewController = segue.destinationViewController;          // Set your custom view controller's delegate         customViewController.delegate = self;     } } 
like image 116
Marco Avatar answered Dec 21 '22 11:12

Marco