I have two UITableViewControllers
and need to pass the value from the child view controller to the parent using a delegate. I know what delegates are and just wanted to see a simple to follow example.
Thank You
I have two UITableViewControllers
and need to pass the value from the child view controller to the parent using a delegate. I know what delegates are and just wanted to see a simple to follow example.
Thank You
You need to use delegates and protocols. Here is a site with an example http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html
Following solution is very basic and simple approach to send data from VC2 to VC1 using delegate .
PS: This solution is made in Xcode 9.X and Swift 4
Declared a protocol and created a delegate var into ViewControllerB
ViewControllerA confirms the protocol and expected to receive data via delegate method sendData
Simple example...
Let's say the child view controller has a
UISlider
and we want to pass the value of the slider back to the parent via a delegate.In the child view controller's header file, declare the delegate type and its methods:
ChildViewController.h
In the child view controller's implementation, call the delegate methods as required.
ChildViewController.m
In the parent view controller's header file, declare that it implements the
ChildViewControllerDelegate
protocol.RootViewController.h
In the parent view controller's implementation, implement the delegate methods appropriately.
RootViewController.m
Hope this helps!
This below code just show the very basic use of delegate concept .. you name the variable and class as per your requirement.
First you need to declare a protocol:
Let's call it MyFirstControllerDelegate.h
Import MyFirstControllerDelegate.h file and confirm your FirstController with protocol MyFirstControllerDelegate
In the implementation file, you need to implement both functions of protocol:
in your SecondController:
In the implementation file of SecondController.
Here is the wiki article on delegate.