我有一个名为SAVE的Bar Button,当它运行的程序自动显示SAVE的标题但是当我编辑该特定视图中的内容时,标题应该改为EDIT是否有可用的编码?
There is indeed a solution for this, and its called editButtonItem()
.
What you need to do is add this in your viewDidLoad:
self.editButtonItem().action = "yourAction"
self.navigationItem.leftBarButtonItem = self.editButtonItem()
If you have the instance of your UIBarButtonItem
then you can try doing the below code I suppose you have your object with the name "objSaveButton".
[objSaveButton setTitle:@"EDIT"];
or if you don't have the instance you can get the same from UINavigationController
if it is your left bar button item do this: [navigationController.navigationItem.leftBarButtonItem setTitle:@"EDIT"];
and if it is your right bar button do this:
[navigationController.navigationItem.rightBarButtonItem setTitle:@"EDIT"];
Set the tag in your button.
-(IBAction) add:(id)sender
{
if([sender tag] == 0){
// set the button title as "Save"
}
else{
// set the button title as "Edit"
Button1.tag=0;
}
}
Hope this will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.