I have implemented a custom alertview and the delegate
methods are as follows:
#import <UIKit/UIKit.h>
@class MyAlertViewController;
@protocol MyAlertViewControllerDelegate <NSObject>
@required
-(void) alertViewControllerClickedPrimaryButton:(MyAlertViewController *)alertViewController;
@optional
-(void) alertViewControllerClickedSecondaryButton:(MyAlertViewController *)alertViewController;
@end
I have these delegate methods called in many view controllers.And Also I made one SharedViewController
which I use it for all my ViewControllers
Lets say, one of these delegate method is called from MasterViewController
which inherits SharedViewController
,I will have this method in the SharedViewController
:
#pragma mark My Alert Delegate
-(void) alertViewControllerClickedPrimaryButton:(MyAlertViewController *)alertViewController{
//here how would I know that this alert is presented from MasterViewController ?
}
If I do [self class]
, I would get the name as SharedViewController
.
How can I get the name for my MasterViewController
in my SharedViewController
,when the delegate
method is called from MAsterVIewController
?
Edit: I added one parameter called UIViewController
to the delegate method,and now it looks like this:
-(void) alertViewControllerClickedSecondaryButton:(MyAlertViewController *)alertViewController :(UIViewController *)controllerName;
and what needs to send to delegate as controllerName?
I have this line to call the delegate method:
[_delegate alertViewControllerClickedSecondaryButton:self ]; //previous call
and I changed this to:
[_delegate alertViewControllerClickedSecondaryButton:self :<#(UIViewController *)#>]; // I have no idea which parameter to pass in here
any ideas?
~ EDIT ~
MasterViewController
Lastly, Tick the 'Use Storyboard ID' box √
Now, in your Alert Delegate Method after your custom AlertVC has been presented onto the Navigation Stack:
-(void) alertViewControllerClickedPrimaryButton:(MyAlertController *)alertViewController
{
/* ... all other code
...
...
*/
// Print the name of the Presenting View Controller
NSLog(@"Presenting ViewController = %@", self.presentingViewController.restorationIdentifier);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.