Doing a push segue using a custom UIBarButton

I have this code that lets me create a custom UIBarButton which is inside my viewDidLoad.

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                               style:UIBarButtonItemStyleDone
                                                              target:nil
                                                              action:nil];
    self.navigationItem.rightBarButtonItem = doneButton;

Now, I want this method below to be called when the UIBarButton is pressed so that a segue to the next view controller will be done.

- (void) didPressDone {

    PointsResultsViewController *pointsResults = [self.storyboard instantiateViewControllerWithIdentifier:@"resultsPointsVC"];

    [self.navigationController pushViewController:pointsResults animated:YES];
}

I've done some research regarding this. However the ones I saw were all about dragging a UIBarButton to the ViewController from the Object Library then just wire it up to the next VC, have the method prepareForSegue, done, simple as that. In my case, it's quite different.

Advice please :)

Answers


You can set the target to self and the action to your didPressDone selector:

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                               style:UIBarButtonItemStyleDone
                                                              target:self
                                                              action:@selector(didPressDone:)];

The selector should have a signature like this:

- (void)didPressDone:(id)sender

Need Your Help

Should DTO and Entity both have input validations

c# wcf validation nhibernate domain-driven-design

I have a WCF layer and my Domain Model is behind this WCF layer. I am using Nhibernate as an ORM tool and all my business logic/ Data Access etc will be behind this WCF layer.