我正在使用此方法尝试获取我的一个类中的UIScrollView的属性:

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];
    }


当前已加载类SGInitialViewController,并且其childViewController SGPlotViewController也已加载并且也在屏幕上。
无论如何努力,我都无法更改其属性。
关于我在做什么错的任何想法吗?

最佳答案

如果不了解您的应用程序的整体结构,就很难知道问题出在哪里。但是,深入研究所有这些控制器以获取属性并不是一个好的设计。如果可以使用委托,则应该这样做-有时,尽管如此,根据所有这些控制器的设置方式,很难获得正确的引用,因此类可以将自身设置为委托。在这种情况下,最好使用通知。哪一个类包含您的问题中的代码,都应发布通知,并且应该注册SGPlotViewController以接收该通知。

07-28 03:31
查看更多