user3312399
user3312399

Reputation: 35

UIContainerView call parent method

I am a very new iOS dev and need your help.

I have a simple app, made from:

1 view controller that contains

Here is an image of my storyboard so it will be easier to understant: enter image description here => I need 10 rep to post the image as an image

What I want is that when I click the play button on the cell inside "View Controller Search" it calls a method or function from the parent (main?) view controller including the url of the file to play.

I have already a working action on the play button, I have found how to get the url from it and printed it using NSLog so everything is fine from this part. My only problem is to find a way to communicate with the main view by sending the url.

If hope I am clear enough, thank you for your time.

Upvotes: 1

Views: 533

Answers (1)

jrturton
jrturton

Reputation: 119242

You've got two options:

  1. The quick and dirty one is to use the parentViewController property of your contained controller, cast it to the type of the parent view controller and call a method on it.
  2. The right way is to define a delegate protocol and property for your search view controller, and make the parent view controller conform to it. Then, in the prepareForSegue: of the parent view controller, set the parent as the search controller's delegate.

prepareForSegue: will be called three times when your parent view controller is loaded, once for each embed segue that you have defined in the storyboard above. Just like when you push on a navigation controller, this is your opportunity to configure the destination view controller. You can give each embed segue in your storyboard an identifier to help with this process.

Upvotes: 1

Related Questions