是否可以从appDelegate访问视图控制器的方法,就像使用以下代码进行反向操作一样:
AppDelegate *ad = (AppDelegate *) [[UIApplication sharedApplication] delegate];当我尝试的时候
ViewController *vc = (ViewController *) [[UIApplication sharedApplication] delegate];我得到了一个错误...
谢谢!
发布于 2012-06-27 19:43:05
ViewController *vc = (ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;或者如果您的委托具有属性
YourAppDelegate *ad = (YourAppDelegate*)[UIApplication sharedApplication].delegate;
ViewController *vc = ad.yourViewControllerProperty;发布于 2012-06-27 20:56:38
在您的AppDelegate中,假设viewController是您的rootViewController,您可以通过以下命令获得堆栈上所有视图控制器的列表:
NSLog(@"List of current active view controllers:%@", self.viewController.navController.viewControllers);要访问viewControllers中的特定视图控制器,请执行以下操作:
[[self.viewController.navController.viewControllers objectAtIndex:i] someMethodOfThatViewController]; https://stackoverflow.com/questions/11225203
复制相似问题