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

后端 未结 1 785
后悔当初
后悔当初 2021-01-12 10:24

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

In my selection list .h I have:

#import 

        
1条回答
  •  不知归路
    2021-01-12 11:13

    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.

    0 讨论(0)
提交回复
热议问题