我有一个视图,它有一个带两个按钮的navigationController,START(基本上是一个登录按钮)和SETTINGS。单击“设置”时,将显示设置视图,并按计划解除。我可以单击设置然后单击返回多次而不会发生任何崩溃。好。
现在,当用户单击START时,我调用SHOWLOGOFFBUTTONS方法来更改navController中显示在视图顶部的按钮。 navBar应该(并且确实)现在只有一个LOGOFF按钮。单击该按钮时,我调用SHOWLOGINBUTTONS,因此用户具有与以前相同的登录按钮,因此他们可以再次访问SETTINGS和START(登录)。
问题是,一旦我从LOGIN按钮到LOGOFF按钮的“按钮开关”回到LOGIN BUTTONS,SETTINGS按钮就会停止工作。 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];
}
答案 0 :(得分:1)
您需要释放按钮,因为您正在分配它们。为此,我通常使用autorelease - 尝试:
-(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方法中也这样做。