1.在AppDelegate.h 中定义下面方法;
+(AppDelegate *) app;
2.AppDelegate.m中,加入;
+ (AppDelegate*) app
{
return (AppDelegate*)[[UIApplication sharedApplication] delegate];
}
3.相关操作:
A:
比如你在RootViewController中 定义了 -(void)showHomeView;
全局的操作可以这样: [[AppDelegate app].rootViewController showHomeView];这样 Homeview就Show出来了。
B:如果homeview中还有其他很多子视图呢?
我们可以在HomeViewController中定义好,显示其他子视图(subviews)的方法,比如
-(void)showHcenterView
{
if (hCenterViewController == nil) {
hCenterViewController = [[HCenterViewController alloc]initWithNibName:@"HCenterViewController" bundle:nil];
}
[self.view addSubview:hCenterViewController.view];
}
-(void)hiddenHcenterView
{
[hCenterViewController.view removeFromSuperview];
hCenterViewController = nil;
}
然后当我们需要操作的时候 调用:
[[AppDelegate app].rootViewController.homeViewController showHcenterView];
C:赋值或取值
如果homeViewController 里有一个(UILabel)名字为 name_Lbl,要对其操作,
[AppDelegate app].rootViewController.loginViewController.name_Lbl = @"姓名";