views:

2622

answers:

1

I have a view that has a navigationController with two buttons, START (essentially a login button) and SETTINGS. When I click SETTINGS, the settings view appears and dismisses as planned. I can click on settings and then click back many times without anything crashing. Good.

Now, when a user clicks START, I call the SHOWLOGOFFBUTTONS method to change the buttons that appear at the top of the view, in the navController. The navBar should (and does) now have only a LOGOFF button. When that button is clicked, I call SHOWLOGINBUTTONS so the user has the same login buttons as before, so they can access SETTINGS and START (Login) again.

The problem is, once I do the "button-switch" from LOGIN buttons to LOGOFF buttons back to LOGIN BUTTONS, the SETTINGS button stops working. The SHOWSETTINGS method triggers and runs - no errors occur - but the view does not appear.

Any assistance would be greatly appreciated!!

-(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];
}
+1  A: 

You need to release your buttons because you are allocating them. For this I normally use autorelease - try:

    -(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];
}

Also do the same in your showLogoffButtons method.

Sean
Thanks for the responses, Sean - unfortunately, the problem still persists.
Dutchie432
Did you fix the problem? Just wondering why I was selected as the answer if the problem still persists? :)
Sean
Umm - it's been a while so I will need to check how I got it working. If I recall correctly - the problem was 2-fold and you lead me in the right direction. Thanks Sean!
Dutchie432