- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithTitle:@"Refresh" style:UIBarButtonItemStylePlain target:self action:@selector(refreshButtonClicked:)];
[self.navigationItem setRightBarButtonItem:refreshButton animated:YES];
}
- (void)refreshButtonClicked:(id)sender {
NSLog(@"Refreshed.");
}
I added a navigation controller programmatically in AppDelegate and set this view as the root.
When I was trying to add a navigationItem programmatically as shown above, the refreshButton showed in the navigation bar but refreshButtonClicked: was not invoked.
What’s the problem? Any suggestions and comments are welcome.
Problem solved. Weird. After I clean the builds, delete the derived data and restart Xcode, it goes runs properly.