检查控制器是否已经加载 XCode

发布于 2024-11-09 07:58:54 字数 1133 浏览 4 评论 0原文

我有以下代码来在分割视图控制器中推送新的 ViewController:

Level4ViewController *controller = [[Level4ViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
    [[detailViewController navigationController] pushViewController:controller animated:YES];
    [controller release], controller = nil;

我遇到的唯一问题是,如果我再次运行它,将显示一个新的控制器,我希望能够转到我拥有的视图之前我的所有数据。

任何人都可以帮我吗?

谢谢。

编辑:

更新了代码?

Level4ViewController *controller;
    for(UIView *view in self.navigationController.viewControllers)
    {
        if([view isKindOfClass:[Level4ViewController class]])
        {
            controller = view;
            if(controller == nil)
            {
                controller = [[Level4ViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
            }
            else {
                controller = [self.navigationController.viewControllers objectAtIndex:1];
            }

        }
    }

    [[detailViewController navigationController] pushViewController:controller animated:YES];
    [controller release], controller = nil;

I have the following code to push a new ViewController in a Split View Controller:

Level4ViewController *controller = [[Level4ViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
    [[detailViewController navigationController] pushViewController:controller animated:YES];
    [controller release], controller = nil;

The only problem I have, if I were to run this again, a new controller will show, I would like to be able to go to the view that I had before with all my data.

Can anyone help me out here.

Thanks.

EDIT:

Updated code?

Level4ViewController *controller;
    for(UIView *view in self.navigationController.viewControllers)
    {
        if([view isKindOfClass:[Level4ViewController class]])
        {
            controller = view;
            if(controller == nil)
            {
                controller = [[Level4ViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
            }
            else {
                controller = [self.navigationController.viewControllers objectAtIndex:1];
            }

        }
    }

    [[detailViewController navigationController] pushViewController:controller animated:YES];
    [controller release], controller = nil;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

儭儭莪哋寶赑 2024-11-16 07:58:54

UINavigationController 有一个属性 viewControllers,它是一个 NSArray,它保存已推送到导航控制器的所有堆栈,在这个数组中您可以检查对于你的视图控制器,如果它在那里,请使用那个 - 你像这样检查 -

Level4ViewController *lvc;

for(UIView *view in self.navigationController.viewControllers)
{
     if([view isKindOfClass:[Level4ViewController class]])
     {
          lvc = view;
     }
}

如果你已经知道你的视图控制器在那里的索引,那么你可以从该索引获取它作为 -

Level4ViewController *lvc = [self.navigationController.viewControllers objectAtIndex:1];

更新 -

Level4ViewController *controller;
for(UIView *view in self.navigationController.viewControllers)
{
     if([view isKindOfClass:[Level4ViewController class]])
     {
         controller = view;
     }
}

if(controller == nil)
{
    controller = [[Level4ViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
}

[[detailViewController navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;

UINavigationController has a property viewControllers which is a NSArray that hold all the stack that has been pushed to the navigation controller, in this array you can check for your view controller if it is there use that one - you check like this -

Level4ViewController *lvc;

for(UIView *view in self.navigationController.viewControllers)
{
     if([view isKindOfClass:[Level4ViewController class]])
     {
          lvc = view;
     }
}

and if you already knows that at which index your viewcontroller is there then you can get it from that index as -

Level4ViewController *lvc = [self.navigationController.viewControllers objectAtIndex:1];

update -

Level4ViewController *controller;
for(UIView *view in self.navigationController.viewControllers)
{
     if([view isKindOfClass:[Level4ViewController class]])
     {
         controller = view;
     }
}

if(controller == nil)
{
    controller = [[Level4ViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
}

[[detailViewController navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
寄意 2024-11-16 07:58:54

如果您使用导航控制器

FirstScreenViewController *firstScreenVC = [self.storyboard instantiateViewControllerWithIdentifier:@"1S"];

    if (![self.navigationController.topViewController isKindOfClass:FirstScreenViewController.class])
        [self.navigationController pushViewController:firstScreenVC animated:YES];

If you are using a navigation controller

FirstScreenViewController *firstScreenVC = [self.storyboard instantiateViewControllerWithIdentifier:@"1S"];

    if (![self.navigationController.topViewController isKindOfClass:FirstScreenViewController.class])
        [self.navigationController pushViewController:firstScreenVC animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文