工具栏项目未随视图一起推送

发布于 2024-08-18 22:14:52 字数 1838 浏览 2 评论 0原文

我有一个基于 NavigationController 的 iPhone 应用程序,它有一个导航栏和一个工具栏。它的工作原理基本上如下:

applicationDelegate 将“SplashScreen”作为模态视图推送到 RootViewController 上。当启动屏幕启动时,应用程序会执行一些工作,并根据用户的位置,要么只是关闭模式视图,要么关闭模式视图并将另一个视图推送到导航堆栈上。

RootViewController 和子视图都有带有“添加”按钮的工具栏。我的问题是这样的:当自动推送第二个视图时,“添加”按钮调用其父控制器的代码。如果您忽略此操作,然后再次按添加按钮,它将调用正确的代码。

这是我的一些代码。

在 RootViewController 的 viewDidLoad 中,我有:

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
    [self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];

在子控制器(LocationListsController)的 viewDidLoad 中,我有:(

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
    [self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];

是的,相同的代码,它们都有 addClicked 事件)

在 RootViewController 中,viewWillAppear 是我实际推送子视图的位置

if (((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex != -1)
    {
        GeoLocation *location = [((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).locations objectAtIndex:((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex];
        ((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex = -1;

        if (lController == nil)
        {
            LocationListsController *aController = [[LocationListsController alloc] initWithLocation:location];
            self.lController = aController;
            [aController release];
        }

        [[self navigationController] pushViewController:lController animated:YES];
    }

:的视图效果很好。我遇到的唯一问题是工具栏上的 addButton 。有人有什么想法吗?

I have a NavigationController based iPhone app that has a navigationBar and a toolbar. Here is basically how it works:

The applicationDelegate pushes a "SplashScreen" onto the RootViewController as a modal view. While the splash screen is up, the application does some work and based on the user's location will either just dismiss the modal view OR will dismiss the modal view and push another view onto the navigation stack.

Both the RootViewController and the child view have toolbars with an Add button. My problem is this: when the 2nd view is pushed automatically, the Add button calls the code for its PARENT controller. If you dismiss this and then press the add button again, it calls the correct code.

Here is some of my code.

in the viewDidLoad of the RootViewController I have:

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
    [self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];

in the viewDidLoad of the Child Controller (LocationListsController) I have:

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
    [self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];

(yes the same code, they both have addClicked events)

in the RootViewController, viewWillAppear is where I actually push the child view:

if (((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex != -1)
    {
        GeoLocation *location = [((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).locations objectAtIndex:((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex];
        ((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex = -1;

        if (lController == nil)
        {
            LocationListsController *aController = [[LocationListsController alloc] initWithLocation:location];
            self.lController = aController;
            [aController release];
        }

        [[self navigationController] pushViewController:lController animated:YES];
    }

The pushing of the view works fine. The only problem I have is the addButton on the toolbar. Does anyone have any ideas?

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

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

发布评论

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

评论(1

夜无邪 2024-08-25 22:14:52

尝试从 viewDidAppear 而不是 viewWillAppear 推送“子”视图控制器。

Try pushing the "child" view controller from viewDidAppear instead of viewWillAppear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文