簡體   English   中英

使用InstantiateViewControllerWithIdentifier設置自定義委托

[英]Setting custom delegate with instantiateViewControllerWithIdentifier

我使用下面的代碼到presentViewController,其中我設置了委托。

Filters * vc = [storyboard instantiateViewControllerWithIdentifier:@"FilterMe"];
        vc.filtersDelegate = self;
        [self presentViewController:vc animated:YES completion:nil];

但是我收到以下錯誤,

[UINavigationController setFiltersDelegate:]: unrecognized selector sent to instance 0x1018cf600'

我想念什么?

似乎[storyboard instantiateViewControllerWithIdentifier:@"FilterMe"]返回一個UINavigationController

檢查您的情節vc.viewControllers.first ,但您可能需要vc.viewControllers.first才能訪問您的真實視圖控制器。

嘗試:

    UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:@"FilterMe"];
    Filters *vc = navController.viewControllers.firstObject;
    vc.filtersDelegate = self;
    [self presentViewController:navController animated:YES completion:nil];

在情節提要中,您的班級以及導航控制器的檢查標識符都已嵌入其中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM