有没有办法可以执行
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
应用程序从另一个ViewController运行时的方法?
答案 0 :(得分:1)
在您的app委托中维护一个单独的方法,以设置导航栏外观。
在AppDelegate.h文件中,声明相同的方法。
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
-(void)setNavBarAppearance;
@end
在appDelegate.m文件中,编写该方法的功能
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setNavBarAppearance];
}
-(void)setNavBarAppearance {
//Do what is required here.
}
@end
然后,无论你需要调用相同的方法:
#import "AppDelegate.h"
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate setNavBarAppearance];
答案 1 :(得分:0)
您不应该自己调用委托方法,可以使用NSNotificationCenter
someThingInterestingHappened
)编写要执行的代码。addObserver
上致电defaultNotificationCenter
,即[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someThingInterestingHappened:) name:@"desiredEventHappend" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"desiredEventHappend" object:nil];