帮助访问 Objective C iOS 中的属性
我有一个基于导航的项目,我希望能够访问该项目不同类中的属性。
在我的 appDelegate 中,我有属性:
UINavigationController *navig;
然后我设置了 rootViewController:
MainViewController *theMainViewController = [[MainViewController alloc] init];
self.navig = [[UINavigationController alloc] initWithRootViewController:theMainViewController];
在 theMainViewController
对象中,我有属性:
MyScrollView *scrollView;
因此,要访问此 scrollView
> 来自不同类的属性,我尝试了以下操作:
MyAppDelegate *myAppDelegate = (MyAppDelegate*) [UIApplication sharedApplication].delegate;
UIViewController *mainViewController = [myAppDelegate.navig.viewControllers objectAtIndex:0];
UIScrollView *scroll = mainViewController.scrollView;
但是,它不起作用。它似乎没有找到 scrollView
属性。我做错了什么吗?非常感谢!
I have a navigation based project and I want to be able to access properties in the different classes of the project.
In my appDelegate I have the property:
UINavigationController *navig;
and then I set the rootViewController
:
MainViewController *theMainViewController = [[MainViewController alloc] init];
self.navig = [[UINavigationController alloc] initWithRootViewController:theMainViewController];
In the theMainViewController
object I have the property:
MyScrollView *scrollView;
So, to access this scrollView
property from a different class, I tried the following:
MyAppDelegate *myAppDelegate = (MyAppDelegate*) [UIApplication sharedApplication].delegate;
UIViewController *mainViewController = [myAppDelegate.navig.viewControllers objectAtIndex:0];
UIScrollView *scroll = mainViewController.scrollView;
However, it is not working. It doesn't seems to find the scrollView
property. Am I doing something wrong? Thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何拒绝财产?
您还应该设置适当的
mainViewController
类型:它应该是MainViewController
:How do you decline properties?
Also you should set appropriate type of
mainViewController
: it should beMainViewController
: