[英]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文件,這似乎工作正常。 idk為什么我無法獲得上面的代碼來做完全相同的事情。
var dVC = DriverViewController()
self.navigationController?.pushViewController(dVC, animated: false)
在Objective-C中,即使頭文件是用Swift編寫的,也需要導入頭文件。 為此,您需要一個傘頭。 蘋果在文檔中對此進行了介紹。 它會告訴您如何在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
您在使用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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.