2016-01-06 2 views
6

Ho creato un framework con un controller di visualizzazione denominato "AuthenticationViewController.h" con pennino "AuthenticationViewController.xib". E un progetto di esempio da testare è stato utilizzato per presentare AuthenticationViewController. In Objective-C:Come presentare un controller di visualizzazione da un framework esterno in swift?

NSString *frameworkDirPath = [[NSBundle mainBundle] privateFrameworksPath]; 
NSString *frameworkBundlePath = [frameworkDirPath stringByAppendingPathComponent:@"SendOTPFramework.framework"]; 
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath]; 
AuthenticationViewController *authenticationViewController = [[AuthenticationViewController alloc]initWithNibName:@"AuthenticationViewController" bundle:frameworkBundle]; 
authenticationViewController.delegate = self; 
[self presentViewController:authenticationViewController animated:YES completion:nil]; 

che funziona bene per me.

Ma quando io uso seguente codice nel Swift:

let frameworkBundle = NSBundle(identifier: "SendOTPFramework") 

let authViewControler :AuthenticationViewController = AuthenticationViewController.init(nibName: "AuthenticationViewController", bundle: frameworkBundle) 
authViewControler.delegate = self 
self.presentViewController(authViewControler, animated: true, completion: nil) 

Arresto anomalo dell'applicazione con l'errore: -??

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'AuthenticationViewController''

risposta

2

NSBundle(identifier: "SendOTPFramework"), non NSBundle(path: <#T##String#>) Sei sicuro che ci sia un identificatore disponibile Hai usato diversa funzione in diverse lingue.

+0

È "identificativo" l'identificatore del bundle del framework incluso nel progetto. O il nome del framework incluso. –

+0

@HussainChhatriwala L'identificatore del bundle del framework. Puoi anche usare la funzione di traccia in rapido. – Lumialxk

+0

Quanto sopra ha funzionato in grado di aprire il controller. ma l'app continua a bloccarsi dopo pochi secondi sul delegato dell'app senza alcun registro degli arresti anomali. –