[英]Bar Button Item Issue
我有一個名為SAVE的Bar Button,當它運行的程序自動顯示SAVE的標題但是當我編輯該特定視圖中的內容時,標題應該改為EDIT是否有可用的編碼?
確實有一個解決方案,它的名字叫editButtonItem()
。
您需要做的是在viewDidLoad中添加:
self.editButtonItem().action = "yourAction"
self.navigationItem.leftBarButtonItem = self.editButtonItem()
如果您有UIBarButtonItem
的實例,那么您可以嘗試執行以下代碼,我假設您的對象名為“objSaveButton”。
[objSaveButton setTitle:@"EDIT"];
或者如果你沒有實例,你可以從UINavigationController
獲得相同的實例
如果它是你的左欄按鈕項目,請執行以下操作: [navigationController.navigationItem.leftBarButtonItem setTitle:@"EDIT"];
如果是你的右鍵按鈕,請執行以下操作:
[navigationController.navigationItem.rightBarButtonItem setTitle:@"EDIT"];
在按鈕中設置標簽。
-(IBAction) add:(id)sender
{
if([sender tag] == 0){
// set the button title as "Save"
}
else{
// set the button title as "Edit"
Button1.tag=0;
}
}
希望這會幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.