简体   繁体   English

UIViewController obj在mycustomview控制器实现中已更新,如何在子类中获取它

[英]UIViewController obj updated in mycustomview controller implementation how to get it in a subclass

i created a myCustomviewcontroller and made all other .m files as subclasses to it. 我创建了一个myCustomviewcontroller并将所有其他.m文件作为其子类。

and myCustomviewcontroller contains an UIViewController obj and property defined as: 并且myCustomviewcontroller包含UIViewController obj和定义为以下属性的属性:

@interface MyCustomViewController : UIViewController{
    IBOutlet UINavigationController *navigationController;
        UIViewController *topView;

}

@property(nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property(nonatomic, retain) IBOutlet UIViewController *topView;


@end

in the implementation the topview is initialized or given a view controller as in 在实现中,topview被初始化或被赋予一个视图控制器,如

@implementation MyCustomViewController

//some method
    topView = appDelegate.navigationController.topViewController;
@end

and there is another class demo.h which uses MyCustomViewController 还有另一个类demo.h,它使用MyCustomViewController

@interface demo : MyCustomViewController{
}

and in the implementation of demo.mi want to get the topview value. 并在demo.mi的实现中希望获得topview值。 not just the instance of topview but the value which is assigned to topview in the implementation of MyCustomViewController.m is this possible if so please help me 不仅可能是topview的实例,还可以在MyCustomViewController.m的实现中分配给topview的值,如果有的话,请帮助我

thanks. 谢谢。

By the rule of inheritance you can use the instance variable of base class or super class. 根据继承规则,您可以使用基类或超类的实例变量。 so i will prefer you whenever you use inheritance you initialise the property in derived class not in super class so in your case you initialise 所以无论您何时使用继承,我都希望您在不属于超类的情况下在派生类中初始化属性,因此在您的情况下,您可以对

super.topView = appDelegate.navigationController.topViewController; super.topView = appDelegate.navigationController.topViewController;

in demo not in MyCustomViewController. 在演示中不在MyCustomViewController中。

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

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