IOS developmentOn UIBarButtonItemButtonThe example of switching or hiding a case is described in this article. The background of this code example is: the navigation bar has an edit button on the right, and the back button and add button on the left. Code ImplementationButtonThe switch/hide function is specific: Click edti button, the back button is hidden, and the add button is displayed.
After the user completes editing, the back button is displayed to hide the add button. This function is used in many applications, and it is useless to hide it properly.ButtonIt makes sense to keep the interface concise and guide user operations.
Code
- - (void)viewDidLoad {
- [super viewDidLoad];
- selfself.navigationItem.rightBarButtonItem = self.editButtonItem;
- }
- - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
-
- [super setEditing:editing animated:animated];
-
- // Don't show the Back button while editing.
- [self.navigationItem setHidesBackButton:editing animated:YES];
-
- if (editing) {
- self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
- target:self action:@selector(insertMe)] autorelease];
- }else {
- self.navigationItem.leftBarButtonItem = nil;
- //self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
- target:self action:@selector(backButton) ] autorelease];
- }
-
- }
Among them, the back button is the system default. You can add otherButton.
Summary:IOS developmentOn UIBarButtonItemButtonAfter you have finished the introduction of switching or hiding cases, I hope this article will help you!