title: Objective C UIBarButtonItem as toggle button for edit and save
body: <p>I have written a code to place a right bar button item with customview.While selecting edit it changes to save option.Now I selecting save it saves the values.If again I try to select edit the action not firing.The code I written below,</p>
  
  <pre><code>item = [[UINavigationItem alloc]init];    
  btnn = [UIButton buttonWithType:UIButtonTypeCustom];
  [btnn setFrame:CGRectMake(0, 0, 40, 40)];
  btnn.layer.masksToBounds = NO;
  btnn.layer.cornerRadius = 8.0;
  [btnn addTarget:self action:@selector(rightBarButtonCustomPressed:) forControlEvents:UIControlEventTouchUpInside];
  [btnn setImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
  UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnn];   
  item.rightBarButtonItem = rightBtn;
  self.navigationBar.items = @[item];
  </code></pre>
  
  <p>-(IBAction)rightBarButtonCustomPressed:(UIBarButtonItem*)btn
  {</p>
  
  <pre><code>item = [[UINavigationItem alloc]init];
  btnn = [UIButton buttonWithType:UIButtonTypeSystem];
  [btnn setFrame:CGRectMake(0, 0, 40, 40)];
  btnn.layer.masksToBounds = NO;
  btnn.layer.cornerRadius = 8.0;
  [btnn addTarget:self action:@selector(saveBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  [btnn setTitle:@"save" forState:UIControlStateNormal];
  UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnn];
  item.rightBarButtonItem = rightBtn;       
  self.navigationBar.items = @[item];
  
  [self.firstNameText setEnabled:YES];
  [self.lastNameText setEnabled:YES];
  [self.dateOfBirthTxt setEnabled:YES];
  [self.contactNumberlbl setEnabled:YES];
  </code></pre>
  
  <p>}</p>
  
  <p>-(IBAction)saveBtnClicked:(UIBarButtonItem*)btn {</p>
  
  <pre><code>[self.firstNameText setEnabled:NO];
  [self.lastNameText setEnabled:NO];
  [self.dateOfBirthTxt setEnabled:NO];
  [self.contactNumberlbl setEnabled:NO];
  item = [[UINavigationItem alloc]init];
  btnn = [UIButton buttonWithType:UIButtonTypeCustom];
  [btnn setFrame:CGRectMake(0, 0, 40, 40)];
  btnn.layer.masksToBounds = NO;
  btnn.layer.cornerRadius = 8.0;
  [btnn addTarget:self action:@selector(rightBarButtonCustomPressed:) forControlEvents:UIControlEventTouchUpInside];
  [btnn setImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
  UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnn];
  item.rightBarButtonItem = rightBtn;   
  self.navigationBar.items = @[item];
  </code></pre>
  
  <p>I need to achieve barbuttonitem as toggle to save and edit option.Please anybody help me to fix this.Thanks</p>