1.在AppDelegate.h 中定義下面方法;
app
+(AppDelegate *) app;
2.AppDelegate.m中,加入;
spa
+ (AppDelegate*) app { return (AppDelegate*)[[UIApplication sharedApplication] delegate]; }
3.相關操做:
A:
好比你在RootViewController中 定義了 -(void)showHomeView;code
全局的操做能夠這樣: [[AppDelegate app].rootViewController showHomeView];這樣 Homeview就Show出來了。
B:若是homeview中還有其餘不少子視圖呢?
咱們能夠在HomeViewController中定義好,顯示其餘子視圖(subviews)的方法,好比
rem
-(void)showHcenterView { if (hCenterViewController == nil) { hCenterViewController = [[HCenterViewController alloc]initWithNibName:@"HCenterViewController" bundle:nil]; } [self.view addSubview:hCenterViewController.view]; } -(void)hiddenHcenterView { [hCenterViewController.view removeFromSuperview]; hCenterViewController = nil; }
而後當咱們須要操做的時候 調用: it
[[AppDelegate app].rootViewController.homeViewController showHcenterView];
C:賦值或取值
io
若是homeViewController 裏有一個(UILabel)名字爲 name_Lbl,要對其操做,
class
[AppDelegate app].rootViewController.loginViewController.name_Lbl = @"姓名";