【问题标题】:iPhone SDK - navController pushViewController - not respondingiPhone SDK - navController pushViewController - 没有响应
【发布时间】:2009-04-28 13:51:22
【问题描述】:

我有一个带有两个按钮的 navigationController 视图,START(本质上是一个登录按钮)和 SETTINGS。当我单击设置时,设置视图出现并按计划关闭。我可以单击设置,然后多次单击返回而不会崩溃。很好。

现在,当用户单击 START 时,我调用 SHOWLOGOFFBUTTONS 方法来更改 navController 中显示在视图顶部的按钮。导航栏现在应该(并且确实)只有一个注销按钮。单击该按钮时,我会调用 SHOWLOGINBUTTONS,以便用户拥有与以前相同的登录按钮,因此他们可以再次访问 SETTINGS 和 START(登录)。

问题是,一旦我将“按钮切换”从登录按钮切换到注销按钮再返回登录按钮,设置按钮就会停止工作。 SHOWSETTINGS 方法触发并运行 - 没有发生错误 - 但视图没有出现。

任何帮助将不胜感激!

-(void)showLoginButtons{
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(tryConnection)];
}

-(void)showLogoffButtons{
    self.navigationItem.rightBarButtonItem=nil;
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Logoff" style:UIBarButtonItemStylePlain target:self action:@selector(resetConnectionAndScreen)];
}

-(void)showSettings{
    SettingsViewController *mySettingsViewController= [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
    iPhone_PNPAppDelegate *mainDelegate = (iPhone_PNPAppDelegate *)[[UIApplication sharedApplication] delegate];
    mySettingsViewController.settings=mainDelegate.settings;
    [[self navigationController] pushViewController:mySettingsViewController animated:YES];
    [mySettingsViewController release];
}

【问题讨论】:

    标签: iphone cocoa-touch uiviewcontroller uinavigationcontroller


    【解决方案1】:

    您需要释放按钮,因为您正在分配它们。为此,我通常使用自动释放 - 尝试:

        -(void)showLoginButtons{
        self.navigationItem.rightBarButtonItem=[[[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)] autorelease];
        self.navigationItem.leftBarButtonItem=[[[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(tryConnection)] autorelease];
    }
    

    也在你的 showLogoffButtons 方法中做同样的事情。

    【讨论】:

    • 感谢您的回复,肖恩 - 不幸的是,问题仍然存在。
    • 您解决了这个问题吗?只是想知道如果问题仍然存在,为什么我被选为答案? :)
    • 嗯 - 已经有一段时间了,所以我需要检查一下我是如何工作的。如果我没记错的话 - 问题是 2 倍,你引导我朝着正确的方向前进。谢谢肖恩!
    猜你喜欢
    • 1970-01-01
    • 2019-01-17
    • 2021-08-30
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 2021-03-04
    • 2015-09-02
    • 1970-01-01
    相关资源
    最近更新 更多