'Appdelegate'没有可见的@interface声明选择器'setupTabBarController'

4

我已经在 Appdelegate.m 文件中创建了一个方法。

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

现在我想在ABC.m中访问setupTabBarController

我已经包含了应用程序委托:

#import "AppDelegate.h"

然后:

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

但是它显示错误,

'Appdelegate'没有声明'setupTabBarController'选择器的可见@ interface

我错在哪里了?

3个回答

9
正如错误提示所述,你需要在 AppDelegate.h 中声明它,然后你应该这样调用它:
AppDelegate *maindelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[maindelegate setupTabBarController];

在AppDelegate.h文件中:
@interface AppDelegate : UIResponder <UIApplicationDelegate>

- (void)setupTabBarController;

@end

再检查一遍,我确定你没有在AppDelegate.h类中声明。 - iDev
@Shyantanu,很高兴知道这个消息。 :) - iDev

1

您需要在Appdelegate.h文件中声明此方法,以便在另一个视图控制器中使用它,如下所示:

-(void)setupTabBarController;

1
使用:
AppDelegate *appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setupTabBarController];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接