rkb
rkb

Reputation: 11231

Changing the behavior of UIBarButtonItem i.e shifting from action to segue and vice-a-versa

I have a UIBarButtonItems, left side is edit and right side is add/done;

Now When edit is not clicked the action for right side button is to take me to next view controller and I have setup this using segue in storyboard.

However when edit is clicked I want to perform a different action i.e I don't want to go to that new view controller rather disable editing when clicked on that right side UIBarButtonItem.

Now I also have a IBAction done; which disables the editing.

But how to shift the behavior between add/done;

I can do this via programming; But since I have added the segue via storyboard, I wanted to know if there is a way I can switch between segue from storyboard and the IBAction in my controller.

Thanks.

Upvotes: 0

Views: 61

Answers (1)

Anton Gaenko
Anton Gaenko

Reputation: 9025

Your problem is that you connect button action to perform specific segue. You can

  • create segue between your controllers by Ctrl+dragging from one VC to another (not from specific view to view controller). You can do it easily in VC list window (to the left of your Storyboard scene). Don't forget give IDs to your segues.
  • connect your button actions to VC action listeners
  • in these listeners use your logic and invoke with specific identifier
    - (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender

That's all!

Upvotes: 3

Related Questions