Storyboard - setting delegates

前端 未结 2 1052
无人及你
无人及你 2020-12-13 20:06

Before storyboards I was able to set delegates and datasources just by dragging an outlet to a class. With storyboards, I cannot drag the outlet to another view controller;

2条回答
  •  孤街浪徒
    2020-12-13 20:40

    Correct. Set the delegate or other data in your prepareForSegue:sender: method. Here is an example:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        // Check the segue identifier
        if ([segue.identifier isEqualToString:@"showDetail"])
        {
            // Get a reference to your custom view controller
            CustomViewController *customViewController = segue.destinationViewController;
    
            // Set your custom view controller's delegate
            customViewController.delegate = self;
        }
    }
    

提交回复
热议问题