Properly accessing a segue's destination view controller to assign protocol delegates

I’m encountering some problems in integrating segue and protocols while implementing a selection list.

In my selection list .h I have:

  • Xcode Swift 3: Timer and Segue View Controller Error
  • perform segue and send tuple as sender
  • Unwind segue and nav button items not triggering after tab bar controller added
  • prepareForSegue : how can I set an if-condition?
  • How to execute some code after a segue is done?
  • Pushing a navigation controller is not supported error message
  • #import <UIKit/UIKit.h>
    @protocol SelectionListViewControllerDelegate <NSObject>
    - (void)rowChosen:(NSInteger)row;
    @interface SelectColor : UITableViewController <NSFetchedResultsControllerDelegate>
    @property (nonatomic, strong) id <SelectionListViewControllerDelegate> delegate;

    In my selection list .m I have:

    @implementation SelectColori
    @synthesize delegate;
    //this method is called from a button on ui
        [self.delegate rowChosen:[lastIndexPath row]];
        [self.navigationController popViewControllerAnimated:YES];

    I would like to access to this selection list view by performing a segue from another table view:

    @implementation TableList
    - (void)selectNewColor
        SelectColor *selectController = [[SelectColor alloc] init];
        selectController.delegate = (id)self;
        [self.navigationController pushViewController:selectController animated:YES];
        //execute segue programmatically
        //[self performSegueWithIdentifier: @"SelectColorSegue" sender: self];
    - (void)rowChosen:(NSInteger)row
        UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error Title" message:@"Error Text" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];

    If I navigate to the selection list using:

    [self.navigationController pushViewController:selectController animated:YES];

    the alert is displayed. If I instead use:

    [self performSegueWithIdentifier: @”SelectColorSegue” sender: self];

    no alert is displayed, because, I think, I don’t pass to the destination selection list the selectController. Any ideas to solve this issue please?

    Solutions Collect From Internet About “Properly accessing a segue's destination view controller to assign protocol delegates”

    When using Segue to pass data to the destinationViewController you need to use the method

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([segue.identifier isEqualToString:@"SelectColorSegue"]) {
            SelectColor *vc = segue.destinationViewController;
            vc.delegate = self;

    from the Apple Docs

    The default implementation of this method does nothing. Subclasses can
    override it and use it to pass any relevant data to the view
    controller that is about to be displayed. The segue object contains
    pointers to both view controllers among other information.