I am trying to add a 'reset' button to a nav-bar added by the UINavigationController. The button is connected to a function that updates the view. For some reason, it is not updating the view. It works fine when it is connected to a different button (not on the nav-bar).
AppDelegate:
In the View:
Button Function:
Nested Function:
EDIT:
I found the solution by playing around. To those interested, I took the navbar item addtions out of viewdidload and put them into init
AppDelegate:
Code:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
gameViewController = [[GameViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:gameViewController];
[window setRootViewController:navController];
[navController release];
[window makeKeyAndVisible];
return YES;
}
In the View:
Code:
- (void)viewDidLoad {
NSLog(@"ViewDidLoad");
UIBarButtonItem *resetGameButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Reset Game"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(resetGameButtonPressed:)] autorelease];
self.navigationItem.leftBarButtonItem = resetGameButtonItem;
Code:
- (IBAction)resetGameButtonPressed:(id) sender{
[gs resetGame];
[self updateViewWithGameState];
}
Nested Function:
Code:
- (void)updateViewWithGameState{
progressView.progress = 1.0/[gs maxScore]*[gs currentScore];
scoreText.text = [NSString stringWithFormat:@"%d",
[gs currentScore]];
[rollButton setImage:[UIImage
imageNamed:[diceImageNames objectAtIndex:([gs lastRoll]-1)]]
forState:UIControlStateNormal];
[tableView reloadData];
}
EDIT:
I found the solution by playing around. To those interested, I took the navbar item addtions out of viewdidload and put them into init
Code:
- (id) init;{
[super init];
UIBarButtonItem *resetGameButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Reset Game"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(resetGameButtonPressed:)] autorelease];
self.navigationItem.leftBarButtonItem = resetGameButtonItem;
return self;
}
Last edited: