简体   繁体   English

无法从一个视图控制器推到下一个

[英]Can't Push from one view controller to the next

I can't push from one view controller to the next. 我不能从一个视图控制器推到下一个。 I keep getting the errors Use of undeclared identifier 'DriverViewController' 我不断收到错误消息Use of undeclared identifier 'DriverViewController'

DriverViewController *vC = [[DriverViewController alloc] init];

[self.navigationController pushViewController:vC animated:YES];

I created another swift file and this seemed to work just fine. 我创建了另一个swift文件,这似乎工作正常。 Idk why I cant get the code above to do the exact same thing. idk为什么我无法获得上面的代码来做完全相同的事情。

var dVC = DriverViewController()

self.navigationController?.pushViewController(dVC, animated: false)

在此处输入图片说明

In Objective-C, you need to import your header files, even if they are written in Swift. 在Objective-C中,即使头文件是用Swift编写的,也需要导入头文件。 To do that, you need an umbrella header. 为此,您需要一个伞头。 Apple has covered this in the documentation. 苹果在文档中对此进行了介绍。 It will tell you how to exactly import Swift files in Objective-C, but simply put you need to import the umbrella header with this: 它会告诉您如何在Objective-C中精确导入Swift文件,但是简单地说,您需要使用以下命令导入伞头:

#import "ProductModuleName-Swift.h"

Documentation: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_78 文档: https : //developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_78

Are you using StroyBoard? 您在使用StroyBoard吗? If yes then you have to added identifier into your Viewcontroller. 如果是,则必须将标识符添加到Viewcontroller中。

For Ex:- 例如:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    DriverViewController *myVC = (DriverViewController *)[storyboard instantiateViewControllerWithIdentifier:@"DriverViewControllerID"];

Or 要么

DriverViewController *myObj = [self.storyboard instantiateViewControllerWithIdentifier:@"DriverViewControllerID"];
[self.navigationController pushViewController:myObj animated:YES];

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

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