The UINavigationController expects the button to be attached to the view controller for the currently displayed view (the button depends on each view when navigating using the UINavigationController). UIViewController has a navigationItem property in which you need to attach your button, usually in the viewDidLoad method of the displayed view controller.
In your class for aStudentsViewController, define the viewDidLoad method and set the button there:
- (void)viewDidLoad { UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"All Present" style:UIBarButtonItemStylePlain target:self action:@selector(makeAllPresent:)]; self.navigationItem.rightBarButtonItem = myButton; }
You can also do this by setting rightBarButtonItem to your aStudentsViewController outside the class, but I think you will have trouble determining when the navigationItem object is available. It would be something like this:
aStudentsViewController.navigationItem.rightBarButtonItem = myButton;
I don't think this will work until the popover forces everything to boot, but I'm not sure about that. The best way is to put it in the viewDidLoad of your aStudentsViewController object.
source share