2012-11-17 22 views
10

它顯示了一個按鈕,標題爲編輯,當按下它,它改變了標題做如何在編輯模式的實現代碼如下啓用更改編輯/完成按鈕標題UINavigationBar的

我想知道如果有一種方法來將完成按鈕標題更改爲其他內容?

我已經改變了完成按鈕的標題。

我使用的代碼是

self.navigationItem.rightBarButtonItem = self.editButtonItem; 
self.editButtonItem.title = @"Change"; 

現在的編輯是變化

如何使完成別的東西?

回答

9

你可以改變編輯按鈕的標題是這樣的: -

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    // Make sure you call super first 
    [super setEditing:editing animated:animated]; 

    if (editing) 
    { 
     self.editButtonItem.title = NSLocalizedString(@"Cancel", @"Cancel"); 
    } 
    else 
    { 
     self.editButtonItem.title = NSLocalizedString(@"Edit", @"Edit"); 
    } 
} 

它的工作就像編輯: -

enter image description here

TO

enter image description here

+0

完美,非常感謝:) – aLFaRSi

+0

接受的答案,如果有用的THX ...隊友 –

+0

我做到了,但它是告訴我等待一段時間:) – aLFaRSi

7

這裏是改變我的方法噸斯威夫特

override func setEditing (editing:Bool, animated:Bool) 
{ 
    super.setEditing(editing,animated:animated) 
    if (self.editing) { 
     self.editButtonItem().title = "Editing" 
    } 
    else { 
     self.editButtonItem().title = "Not Editing" 
    } 
} 
3

大廈Nitin's answer我建議使用內置的UIButtonBar系統項目略有不同的方法。

這會給你的用戶界面系統看起來&的感覺。例如,停止編輯的標準「完成」按鈕在iOS 8上應具有特定的粗體外觀。

此方法還爲您提供免費的字符串本地化。

下面是我得到了代碼:

-(IBAction) toggleEditing:(id)sender 
{ 
    [self setEditing: !self.editing animated: YES]; 
} 

-(void) setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing: editing animated: animated]; 

    const UIBarButtonSystemItem systemItem = 
    editing ? 
    UIBarButtonSystemItemDone : 
    UIBarButtonSystemItemEdit; 

    UIBarButtonItem *const newButton = 
    [[UIBarButtonItem alloc] 
     initWithBarButtonSystemItem: systemItem 
          target: self 
          action: @selector(toggleEditing:)]; 

    [self.navigationItem setRightBarButtonItems: @[newButton] animated: YES]; 
} 

這裏的例子是因爲你的UIViewControllerUINavigationController託管等方面具有UINavigationItem實例的情況。如果您沒有這樣做,您需要以適當的方式更新欄項。

在你viewDidLoad使用下面的調用來配置的編輯按鈕就可以使用:

[self setEditing: NO animated: NO]; 
+1

節省時間的解決方案,無需本地化字符串。 – kelin

相關問題