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

Can't Push from one view controller to the next

我无法从一个视图控制器推送到下一个。我一直收到错误 Use of undeclared identifier 'DriverViewController'

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

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

我创建了另一个 swift 文件,这似乎工作正常。不知道为什么我不能让上面的代码做同样的事情。

var dVC = DriverViewController()

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

您在使用 StroyBoard 吗?如果是,那么您必须在 Viewcontroller.

中添加标识符

例如:-

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

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

在Objective-C中,您需要导入头文件,即使它们是在Swift中编写的。为此,您需要一个伞头。 Apple 在文档中对此进行了介绍。它会告诉你如何在 Objective-C 中准确地导入 Swift 文件,但简单地说你需要用这个导入伞头:

#import "ProductModuleName-Swift.h"

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