Xcode 彻底切换View的方法

来源:互联网 发布:差额计算法步骤 编辑:程序博客网 时间:2024/05/21 16:58

由于首页后面有三个大项目,三个大项目分别使用不同的视图,都没有关联。

所以视图切换不能用简单的push,tab,add,remove,必须彻底替换。

替换的方法很简单,就是把rootViewController换了就OK(换成子页面)。

如果需要,再换回来就是了(回到主页)

代码是在appDelegate上切换View的方法,在子View上调用这个方法,传参数过来指定需要显示哪个View,然后根据参数就可以定制显示哪个View。

在子页面可以保留appDelegate的指针,也可以用shareApplication方法来获取。

- (void)changeViewController:(NSInteger)viewId{    if (viewId==1) {        RootViewController *rootViewCtrl = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil];        [rootViewCtrl setAppDelegate:self];        self.window.rootViewController = rootViewCtrl;        [rootViewCtrl release];        return;    }        CustomersViewController *customerViewCtrl = [[CustomersViewController alloc]initWithNibName:@"CustomersViewController" bundle:nil];    [customerViewCtrl setAppDelegate:self];    self.window.RootViewController = customerViewCtrl;        [customerViewCtrl release];}


原创粉丝点击