【发布时间】:2015-04-21 18:07:27
【问题描述】:
我正在尝试在 iOS 中以编程方式将自定义类名设置为情节提要。
我有带有视图控制器 MyFirstViewController 的情节提要,并将类名设置为 MyFirstViewController
现在我创建另一个视图控制器SecondViewController,它扩展了MyFirstViewController
SecondViewController *vcsecond = (SecondViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"MyFirstViewController"];
[self.navigationController pushViewController:vcsecond animated:YES];
当我运行此应用程序时,我的 SecondViewController viewDidLoad 方法未调用,它调用 MyFirstViewController viewDidLoad 方法。
我得到vcsecond 作为MyFirstViewController 的对象。
请帮助我如何使用MyFirstViewController XIB 打开SecondViewController。
我只想将MyFirstViewController的所有功能继承到SecondViewController,并在这里覆盖一些方法,并在覆盖的方法中执行一些具有附加功能的新代码。
两个视图控制器的设计相同,只是使用覆盖方法添加了一些新功能。
在上面的屏幕 TabSearchForDocViewController 是我的 MyFirstViewController 控制器。
所以我的实际问题是----------
我有两个视图控制器的命令故事板页面。我的 SecondViewController 扩展了 MyFirstViewController。现在我想使用命令故事板页面打开我的 SecondViewController。是否可以通过编程方式设置类名?
【问题讨论】:
-
检查您的标识符名称是否正确“MyFirstViewController”?
-
是的,我检查了很多次都是正确的,但是当我使用上面的代码推送到 SecondViewController 时,它会推送到 MyFirstViewController 类
-
SecondViewController *vcsecond = (SecondViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"MyFirstViewController"];再次检查此行或清理项目并再次运行,请向我展示您的故事板页面。 -
是的,这没关系,但是当我打印 vcsecond 对象时,它返回 MyFirstViewController 类的对象,SecondViewController 是 MyFirstViewController 的子类
-
好的,
nice concept。根据继承规则,这是可能的,但我没有在我的任何项目中这样做。所以祝你好运。
标签: ios objective-c iphone oop