Objective c swift 3-未显示子类视图控制器
在我的Swift 3/Obj-C应用程序中,我在显示Swift视图控制器时遇到问题,该控制器是和Obj-C类的子类 以下代码可以完美地工作: NavigationController.swiftObjective c swift 3-未显示子类视图控制器,objective-c,inheritance,swift3,subclass,viewcontroller,Objective C,Inheritance,Swift3,Subclass,Viewcontroller,在我的Swift 3/Obj-C应用程序中,我在显示Swift视图控制器时遇到问题,该控制器是和Obj-C类的子类 以下代码可以完美地工作: NavigationController.swift func myMethod(){ ... let vc = ParentViewController.init(someParameter: parameter) // << results in desired screen vc?.stringProperty =
func myMethod(){
...
let vc = ParentViewController.init(someParameter: parameter) // << results in desired screen
vc?.stringProperty = "someString"
self.pushViewController(vc!, animated: true)
}
func myMethod(){
...
let vc = SubClassedViewController.init(someParameter: parameter) // << results in blank screen
vc?.stringProperty = "someString"
self.pushViewController(vc!, animated: true)
}
class SubClassedViewController: ParentViewController
{
// nothing in this file yet
}
ParentViewController.h
@interface SuperParentViewController : UIViewController
@property (nonatomic, strong) NSString *stringProperty;
- (instancetype)initWithSomeParameter:(SomeClass *)someParameter;
@end
@interface ParentViewController : SuperParentViewController
// numerous properties are declared here
@end
ParentViewController.m
@implementation ParentViewController
...
- (void)viewDidLoad{
[super viewDidLoad];
// a bunch of properties are set
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// more properties are set
}
...
@end
但是,如果我将ParentViewController子类化,并尝试显示子类“subclass ViewController”,这将导致屏幕上只显示导航栏项;屏幕的其余部分为空白:
NavigationController.swift
func myMethod(){
...
let vc = ParentViewController.init(someParameter: parameter) // << results in desired screen
vc?.stringProperty = "someString"
self.pushViewController(vc!, animated: true)
}
func myMethod(){
...
let vc = SubClassedViewController.init(someParameter: parameter) // << results in blank screen
vc?.stringProperty = "someString"
self.pushViewController(vc!, animated: true)
}
class SubClassedViewController: ParentViewController
{
// nothing in this file yet
}
有人能告诉我为什么SubassedViewController无法显示与ParentViewController相同的内容吗?问题是ParentViewController与.xib文件关联(单击.xib文件->转到标识检查器->在自定义类下,您将找到“ParentViewController”)。因此,当子类化ParentViewController以创建SubassedViewController类时,我还需要使用以下代码来初始化相同的.xib文件: (Swift 3)
我将检查是否调用了超类中的所有视图循环方法。此外,查看Xcode中的视图层次结构可能会有所帮助。