简体   繁体   English

iOS如何从UIViewController访问UIView属性

[英]iOS How can I access UIView property from UIViewController

Can someone Please walk me through the steps because I feel a little stuck and lost 有人可以指导我完成所有步骤,因为我感到有些卡住和迷路

Previous question : iOS - set UIButton target and action from its super class 上一个问题: iOS-从其超类设置UIButton目标和操作

Now I'm trying to get a more general idea - I'm very new to this 现在,我试图获得一个更笼统的想法-我对此很陌生

Help is very appreciated 非常感谢帮助

If you are looking to access the UIView of an associated UIViewController from inside the view controller itself, you simply use self.view . 如果要从视图控制器本身内部访问关联的UIViewController的UIView,则只需使用self.view To access the same UIView from outside of the UIViewController class you would use the instance name of the class plus the .view property. 要从UIViewController类的外部访问同一UIView,可以使用该类的实例名称以及.view属性。 For example: 例如:

//SomeClass.m
- (void)accessVCView
{
   //With a Nib File:
   MyUIViewController *aVCObject = [[MyUIViewController alloc] initWithNibName:@"MyNib" bundle:nil];
   //Or with a Storyboard:
   MyUIViewController *aVCObject = [[UIStoryboard storyboardWithName:@"myStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"MyViewController"];

   UIView *myUIViewControllerView = aVCObject.view;
}

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

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