简体   繁体   中英

No visible @interface for 'Appdelegate' declares the selector 'setupTabBarController'

I have created a method in Appdelegate.m

-(void)setupTabBarController {
         // details goes here
}

Now in ABC.m I want to access the setupTabBarController

I have included app delegate:

#import "AppDelegate.h"

And then:

AppDelegate *maindelegate = [[AppDelegate alloc] init];
[maindelegate setupTabBarController];

But it's showing the error,

No visible @interface for 'Appdelegate' declares the selector 'setupTabBarController'

Where I am wrong?

As the error message states, you need to declare it in AppDelegate.h and then you should call it as:

AppDelegate *maindelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[maindelegate setupTabBarController];

In AppDelegate.h:

@interface AppDelegate : UIResponder <UIApplicationDelegate>

- (void)setupTabBarController;

@end

您必须在Appdelegate.h文件中声明此方法,才能在另一个视图控制器中使用它

-(void)setupTabBarController;

Use :

AppDelegate *appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setupTabBarController];

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM