I'm trying to implement circular dependency between my appDelegate and my viewController to call methods from my appDelegate to my viewController but is not working.
Here is my implementation appDelegate.h:
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong,nonatomic) ViewController *mainView;
appDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
[self.mainView doSomething];
return YES;
}
Here is my implementation on my viewController .h:
#import <UIKit/UIKit.h>
@class AppDelegate;
@interface ViewController : UIViewController
@property (strong,nonatomic) AppDelegate *delegate;
-(void)doSomething;
viewcontroller.m:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
}
-(void)doSomething
{
NSLog(@"doing something");
}
I don't have any errors or warnings but the method doSomething is never been call. any of you knows why or what I'm doing wrong?
I'll really appreciate your help.
from iOS: circular dependency to call method in each other class
No comments:
Post a Comment