【问题标题】:Are there any alternatives to getting the rootViewController besides through app delegate除了通过应用程序委托之外,还有其他方法可以获取 rootViewController
【发布时间】:2016-02-28 18:22:09
【问题描述】:

我正在开发一个深度链接应用程序,我需要将我的深度链接管理器的委托分配给我的 tabbarcontroller 子类

如何从标签栏控制器的子类中返回根标签栏控制器?

这是 app del 函数,我在其中调用 [TMDeeplinkManager searchForPodcast...] [self.mainTabController getMainTabBarController] 我想将其更改为

[TMMainTabBarController mainTabBarController]

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    NSNumber *collectionId = [url host];
    NSString *episodeTitle = [NSString stringWithFormat:@"%@", [url lastPathComponent]];

    [TMDeeplinkManager searchForPodcastWithCollectionID:collectionId
                                                  title:episodeTitle
                                            andDelegate:[self.mainTabController getMainTabBarController]];

    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

这是 tabbarcontroller 的子类,如何在 instancetype 中返回根视图控制器?不使用应用程序del?

@interface TMMainTabBarController () <UINavigationControllerDelegate>

@property (strong, nonatomic) id selectedItem;

@end

@implementation TMMainTabBarController {
    TMMainTabBarController *mainTabBarController;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)didSelectEpisode:(TMPodcastEpisode *)episode {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil] ;
    TMAudioPlayerViewController *audioPlayerViewController = [storyboard instantiateViewControllerWithIdentifier:@"TMAudioPlayerViewController"];

    audioPlayerViewController.episode = episode;

    UINavigationController *mainNavController = self.viewControllers[0];
    [mainNavController pushViewController:audioPlayerViewController animated:true];

}

-(void)setMainTabBarController:(TMMainTabBarController *)tabBarController {
    mainTabBarController = tabBarController;
}

-(TMMainTabBarController *)getMainTabBarController {
    return mainTabBarController;
}

+(instancetype)mainTabBarController {

    return self.mainTabBarController;
}

@end

【问题讨论】:

    标签: ios objective-c instance multiple-instances rootview


    【解决方案1】:
    UIViewController *root = self;
    while (root.parentViewController != nil) {
        root = root.parentViewController;
    }
    

    //中提琴!

    【讨论】:

      猜你喜欢
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      • 2018-04-21
      • 1970-01-01
      • 2017-05-09
      • 2018-03-01
      • 2020-04-17
      相关资源
      最近更新 更多