在viewDidLoad裡,為navigationItem添加名稱為“添加分欄”的按鈕
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.rightBarButtonItem.title = @添加分欄; [self.navigationItem.rightBarButtonItem initWithBarButtonSystemItem:UIBarButtonSystemItemUndo target:self action:@selector(myAction)]; }
-(void)onSelectionChanged:(id)selection { self.navigationItem.rightBarButtonItem.title = @編輯; }
為何直接設置backBarButtonItem的title無效呢?
查看蘋果文檔UIBarButtonItem的父類UIBarItem的title屬性描述:
You should set this property before adding the item to a bar. The default value is nil.故無法修改其title,只能重置這個控件本身。
self.navigationItem.rightBarButtonItem.title = @編輯; [self.navigationItem.rightBarButtonItem initWithBarButtonSystemItem:UIBarButtonSystemItemUndo target:self action:@selector(myAction)];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemUndo target:self action:@selector(changeWellColumnAction)]; temporaryBarButtonItem.title = @編輯; self.navigationItem.rightBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release];