Can't Push from one view controller to the next

325 views Asked by At

I can't push from one view controller to the next. I keep getting the errors 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. Idk why I cant get the code above to do the exact same thing.

var dVC = DriverViewController()

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

enter image description here

2

There are 2 answers

0
imas145 On BEST ANSWER

In Objective-C, you need to import your header files, even if they are written in 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:

#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

2
Yalamandarao On

Are you using StroyBoard? If yes then you have to added identifier into your 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];