大廈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];
}
這裏的例子是因爲你的UIViewController
在UINavigationController
託管等方面具有UINavigationItem
實例的情況。如果您沒有這樣做,您需要以適當的方式更新欄項。
在你viewDidLoad
使用下面的調用來配置的編輯按鈕就可以使用:
[self setEditing: NO animated: NO];
完美,非常感謝:) – aLFaRSi
接受的答案,如果有用的THX ...隊友 –
我做到了,但它是告訴我等待一段時間:) – aLFaRSi