0

我有一个带有两个按钮的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];
}
4

1 回答 1

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 方法中也做同样的事情。

于 2009-04-28T14:24:59.263 回答