我正在尝试根据用户输入在 NavigationBar 中编辑按钮,我需要更改按钮指向的操作和标题。
看来我不能在运行时这样做。
CalendarMonthViewParent.h
#import <UIKit/UIKit.h>
@interface CalendarMonthViewParent : UIViewController
-(void) callChildChange; // This is called from another viewController, telling it to change the button
@property (strong, nonatomic) IBOutlet UINavigationItem *skemaNavigationItem; // this is the Navigation Item in the Storyboard, it has no right btn by default
@end
CalendarMonthViewParent.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// on viewDidLoad i set up the button with an action, via the outlet, this works fine
UINavigationItem *thisNavBar = [self skemaNavigationItem];
UIBarButtonItem *insertBtn = [[UIBarButtonItem alloc] initWithTitle:@"Indsæt" style:UIBarButtonItemStyleBordered target:self action:@selector(insertSkemaItem:)];
thisNavBar.rightBarButtonItem = insertBtn;
}
- (void)callChildChange {
...
// this method is called from another view controller, based on some user input
// this method is supposed to change the button
UINavigationItem *thisNavBar = [self skemaNavigationItem];
// i fetch the button like i did it in viewDidLoad, but i cannot preform operations on it here
// thisNavBar is nil when called here, but it is not nil when called in viewDidLoad?
...
}
如果我的方法不正确且不可能,我将不胜感激任何可行的解决方案
编辑: 我的 UIViewController,不在 UINavigationController 内,我只是在使用 UINavigationbar