I have two controllers
VC A
-> Parent
and VC B
-> Child
Alert view delegate method i.e
func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){}
is declared in VC A
.
When i display alert from VC B
delegate method is not called on alert button clicked.
Create an alert view delegate object in parent class VC A
Implement the delegate in VC B and Set the delegate object in VC B
You are setting
AlertView
delegate to self, Self meansChild
, Change delegate to VC A.Follow these step by step:
Create a protocol in your VC-B as:
Add a var in your VC-B class as:
Use the delegate in any class method of VC-B to send the data to the receiving method (i.e. any method of VC-A), which is any method that adopts the protocol. Follow this pattern to use the delegate:
Adopt the protocol in your recieving class (here, VC-A):
Implement the delegate method in VC-A:
Set the delegate in VC-A where you are instantiating the VC-B object. In my case this is like:
Hope, this helps you for understanding the process of how the delegates work.