繁体   English   中英

如何通过appdelegate在选项卡视图控制器中调用方法。 故事板

[英]how to call a method in a tab view Controller from appdelegate. story board

我需要从应用程序委托中选择一个选项卡上的索引,并在故事板上将选项卡映射到的视图控制器中调用一个函数

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

     NSString *alertMessage = [[userInfo objectForKey:@"aps"] valueForKey:@"alert"];

    if (alertMessage != nil){
         UITabBarController *tabb = (UITabBarController *)self.window.rootViewController;
        tabb.selectedIndex = 2;
     // Need to call a method in my SpecialsViewController which manages properties and functions of tab with index 2
    }
}

请执行下列操作

UITabBarController *tabb = (UITabBarController *)self.window.rootViewController;
UIViewController *controller = [tabb.viewControllers objectAtIndex:index_of_your_view_ SpecialsViewController];
[controller call_your_method];

在你的情况下index_of_your_view_ SpecialsViewController = 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM