I’m using this method to try and get to the property of UIScrollView in one of my classes:
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UINavigationController *nav = delegate.frontViewController.navigationController;
for (UIViewController *controller in nav.viewControllers) {
if ([controller isKindOfClass:[SGInitialViewController class]]) {
SGInitialViewController *sgInitialController = (SGInitialViewController *)controller;
SGPlotViewController *plotVC = [sgInitialController.childViewControllers objectAtIndex:0];
[plotVC.scrollViewMain setUserInteractionEnabled:NO];
}
The class SGInitialViewController is currently loaded and its childViewController SGPlotViewController is loaded and is on screen as well.
I am unable to change the property of it, no matter how hard I try.
Any ideas on what am I doing wrong?
It’s hard to see where the problem is without knowing more about the overall structure of your app. However, digging down through all those controllers to get to a property is just not good design. If it’s possible to use a delegate, you should do that — sometimes, though, depending on how all these controllers are set up, it’s hard to get the right reference so a class can set itself as the delegate. In those cases, it’s probably best to use a notification. Which ever class contains the code you have in your question should post a notification, and the SGPlotViewController should be registered to receive that notification.