I am a very new iOS dev and need your help.
I have a simple app, made from:
1 view controller that contains
3 UIContainerView, each one is linked to its own view controller and class
A view (the player)
Here is an image of my storyboard so it will be easier to understant:
=> 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.
You've got two options:
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.
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.
Related
I have a table view which is embedded in a container view on my main view controller. In my main VC I have a Navigation Bar which has a bar button item that goes to another View controller, which for demonstration purposes I'll call View controller 2. When I hit save on view controller 2 I have an unwind segue to my main vc (the one with the container view). My question is how do I then pass that data to my container view's child.
NOTE: I cannot use NSUserDefaults as I have a custom class which I want to transfer.
I think you should add a delegate to handle this.When 'unwind segue ' was called,just call the delegate for your child view controller. This is the best way.
If you need the data to be shared by all views, you could consider a singleton class - effectively global data.
Here's a tutorial which explains how to use it
I have a main view controller that processes data. I want to send this data and display it in a modal view without using another controller.
I have something like this in my controller:
NSString *myData = #"something";
[self performSegueWithIdentifier:#"MySegue" sender:myData];
I have created a new view in the storyboard and a "Present modally" segue between them. I have created a label in the new view that I would like to change to display the content of myData.
But since there is no controller for this view I can't find a way to link the label to the data. Every advice I find (like PrepareForSegue) is for a two controllers configuration.
Every scene (at least every scene that you want to update custom controls on) should have its own view controller. If you create a scene without a custom view controller class specified, it will still instantiate a standard UIViewController object. Without a custom view controller, you have no way of updating the label on that destination scene.
The standard answer applies here. Give that destination scene its own view controller class, define a custom property in that destination class, have prepareForSegue in the source controller update that custom property in the destination controller, and have the destination view controller's viewDidLoad update the label on the basis of that custom property you set.
In my app i am using PageViewController which has two different View Controllers. I implemented that it works fine. Now what i am trying is to pass some information from MainView Controller to ChildView Controllers when bar button clicked. I tried using protocol,but it doesn't seems to be working.
MainViewController
import ViewControllerA
import ViewControllerB
#protocol MainControllerDelegate<NSObject>
-(void) passInformation :(NSString*)someInfo;
end
MainController<PageViewControllerDelegate>
In
ViewControllerA
What i would like to see is accessing the main controller delegate in child view controller and pass information when some action taken placed in main view controller navigation bar button.
ViewControllerA<MainControllerDelegate> // Can't find the delegate saying undefined
I am sure there will be a way to pass information between UIPageViewController and its Child View controllers. I tried a lot but couldn't find the answer.
Did you import the MainViewController.h file into your ViewControllerA file?
You haven't provided enough information. Post the whole header for both classes, indicating which one is the parent and which is the child. Post the code in the parent view controller that creates the child view controllers. The trick is when you instantiate a view controller that fills one of the pages in your page view controller, you need to set a property in the child that points the child view controller.
I've been working in Mac OS lately, so I'm a bit rusty on page view controllers. If I remember correctly, you pass them an array of the view controllers they manage.
You'd instantiate each of the child view controllers, set up pointers both ways, and then install them in the page view controller.
This is probably a very simple question but I can't find the answer to it.
I am working on a new project that uses Storyboards for the first time.
I have a number of view controllers that connect the way I want them to.
Each view controller has an info button.
I have one view controller (AboutViewController) that I want to use to display the info for all the view controllers. I am currently calling this via a popover segue from each screen. So I have one destination view controller (AVC) that I am calling from a number of VCs- VC1toAVC, VC2toAVC, VC3toAVC etc. I want two textfields in AVC to change, depending on which VC called it.
So here's the problem- how can I tell which view controller called the popup? It's basically the view that's below the popover. Currently I'm storing it as a variable but that's not ideal. I'm guessing it has something to do with the segue identifiers?
Any and all help much appreciated!
One approach to this is adding a property to your pop up view controller and then define the
prepareForSegue:sender:
method so you set your destination view controller's property to the sender of the segue.
Is it possible to create a storyboard segue from a view controller to itself? I have a bunch of Entities that have Related Entities. I'd like to be able to display a Related Entity using the same view controller that's displaying the Entity. But I can't seem to create a segue that will display a new instance of the origin view controller.
Is it just not allowed? Thanks!
Well here's a solution that isn't quite the same but gets me what I want. I found it as an answer to this question.
The reason I thought I had to use a segue rather than the good old programmatic push of a view controller onto the navigation controller's stack is that I had set up the view controller's IBOutlets in the storyboard. I didn't realize that you could create a copy of the view controller as laid out in the storyboard without using a storyboard segue. You can! To see how to do it, check out that other question and up vote the answerer!
You can ctrl-click-drag (or right-click-drag) from an element (UIButton, etc.) to the containing view controller.
(Did you try this? I'm doing it right now; I have one stock UIViewController that just keeps adding itself indefinitely to the containing UINavigationController stack via a normal push segue.)
Yeah, it's annoying I can't do a 'manual' segue to itself.
What I did was added a UIButton to my view and gave it an action of push to the same view controller, and then made this button hidden. Then I can name the segue and reference it in the code.
Hacky, but works.