Pass data between View controllers without using prepareforsegue - ios

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

Related

How pass parameter from parent ViewController of a container view to PageViewController of that container view?

I have three view controllers. The initial view controller has a container view inside it that I want use it as a image slider inside first view controller. So I put some other views inside first VC that show informations about image of container view. For ability to change slides, I use the third VC of type Page View Controller. I want the third VC manage paging for VC of container view. My problem is that I confused in this architecture. I know about dependency injection and delegation pattern and passing parameters from parent to child and vice versa. But How can I pass parameter from first VC to the third VC(Page View Controller) because I want to pass some index data of that parameter to the VC of Container View. Through debugging I saw third VC's View DidLoad never fired. Just Didload's of first VC and second VC fired. How can I solve this situation?
Any help appreciated.
I found the answer.
When we add a container view it create an embedded segue between first VC and second VC. I just need to delete it and create this relation between first and third VC. So now it's what I wanted. I pass my parameter to the third VC(Page View Controller) through segue and from the third VC pass some index of data to the second VC.
Happy Coding!

What do delegates catch with a parent and embedded view controller?

I have a view controller (VC1) which has a container view that holds a table view/VC2.
How I can catch things like scrolling in table view (VC2) but from VC1? Can I use delegates?
Also I am implementing a search feature. Do I have to update the embedded VC2 from VC1, is that also done using delegates?
Now I wonder how I can catch things like scrolling in VC2/table view
but from VC1?
You can catch scrolling in the same VC (in your case VC2), then relay that information to VC1 via custom protocols and delegates.
General principle: You should treat embedded view controllers like any view controller.
For example, when you want to pass data to the parent view controller from the embedded view controller you could relay that via delegates. You would use the prepeForSegue method to set the parent view controller as the delegate.
Similarly, when you want to pass data from the parent view controller to the embedded view controller, you can again pass it via the prepareForSegue method. This time you set data from the parent view controller to an embedded view controller variable.
These principles are true for passing data and delegating responsibility to other view controllers, and embedded view controllers should be treated the same way.

How to pass data between PageViewController and ViewController?

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.

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
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.

How to find the name of the view controller beneath a popover ios7

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.

Resources