0
我创建了自己的私有框架,并将其用作iOS项目中的cocoapods,并且能够访问框架中的所有swift文件,但是当我尝试显示框架的storyboard文件中存在的view时,在iOS项目中出现了崩溃。
详细信息如下:
错误:
2020-06-06 18:02:30.469084+0530 Test[33726:4822657] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x6000024c7300>) doesn't contain a view controller with identifier 'AdditionVC'' *** First throw call stack: ( 0 CoreFoundation 0x0000000106a4c8db __exceptionPreprocess + 331 1 libobjc.A.dylib 0x0000000104fd7ac5 objc_exception_throw + 48 2 UIKitCore 0x00000001094206a9 -[UIStoryboard instantiateInitialViewController] + 0 3 Framework 0x00000001049dcef6 $s22Framework7ManagerC10additionVCSo16UIViewControllerCyFZ + 262 4 Test 0x00000001046d8932 $s17Test14ViewControllerC11viewDidLoadyyF + 178 5 Test 0x00000001046d8a9b $s17Test14ViewControllerC11viewDidLoadyyFTo + 43 6 UIKitCore 0x0000000108c820f7 -[UIViewController loadViewIfRequired] + 1183 7 UIKitCore 0x0000000108be5cf0 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 68 8 UIKitCore 0x0000000108be5fe3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 146 9 UIKitCore 0x0000000108be70a1 -[UINavigationController _startDeferredTransitionIfNeeded:] + 896 10 UIKitCore 0x0000000108be8393 -[UINavigationController __viewWillLayoutSubviews] + 150 11 UIKitCore 0x0000000108bc9041 -[UILayoutContainerView layoutSubviews] + 217 12 UIKitCore 0x0000000109763e69 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417 13 QuartzCore 0x000000010ace6d22 -[CALayer layoutSublayers] + 173 14 QuartzCore 0x000000010aceb9fc _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396 15 QuartzCore 0x000000010acf7d58 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72 16 QuartzCore 0x000000010ac6724a _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328 17 QuartzCore 0x000000010ac9e606 _ZN2CA11Transaction6commitEv + 610 18 UIKitCore 0x000000010929e2c3 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 128 19 CoreFoundation 0x00000001069b3cbc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 20 CoreFoundation 0x00000001069b3480 __CFRunLoopDoBlocks + 336 21 CoreFoundation 0x00000001069add04 __CFRunLoopRun + 1252 22 CoreFoundation 0x00000001069ad4d2 CFRunLoopRunSpecific + 626 23 GraphicsServices 0x000000010eab12fe GSEventRunModal + 65 24 UIKitCore 0x0000000109284fc2 UIApplicationMain + 140 25 Test 0x00000001046d990b main + 75 26 libdyld.dylib 0x0000000107de8541 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
框架结构:
Podspec文件
Pod::Spec.new do |spec| spec.name = "Framework" spec.version = "0.0.4" spec.summary = "Framework to give support to main project." spec.description = "Framework is developed to give additional support to any normal user to create their private profile by adding it in main project." spec.homepage = "https://github.com/my/Framework" spec.license = { :type => "MIT", :file => "LICENSE" } spec.author = { "Tushar Amkar" => "tusharamkar@gmail.com" } spec.platform = :ios, "12.0" spec.source = { :git => "https://github.com/my/Framework.git", :tag => "#{spec.version}" } spec.source_files = "Framework/Framework/**/*.{swift,otf,storyboard}" spec.resource_bundles = { 'Framework' => ['Framework/Framework/**/*.{storyboard}'] } spec.exclude_files = "Classes/Exclude" spec.swift_version = "5.0" end
我试图显示从不同参考网站获得的viewcontroller文件但无法正常工作的代码:
代码1
let storyboard = UIStoryboard(name: "Main", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "AdditionVC") as! AdditionVC self.navigationController?.pushViewController(controller, animated: true)
代码2
let podBundle = Bundle(for: AdditionVC.self) if let bundleURL = podBundle.url(forResource: "Framework", withExtension: "bundle") { if let bundle = Bundle(url: bundleURL) { let storyBoard = UIStoryboard.init(name: "Main", bundle: bundle) if let vc = storyBoard.instantiateViewController(withIdentifier: "AdditionVC") as? AdditionVC { self.navigationController?.pushViewController(vc, animated: true) } } }
我已经签入了我们当前正在使用的其他Pod,因此下面的代码可以正常工作(尽管这是客观的,但在这种情况下我认为语言并不重要):
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Applozic" bundle:[NSBundle bundleForClass:[self class]]]; ALGroupDetailViewController * groupDetailViewController = (ALGroupDetailViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ALGroupDetailViewController"]; groupDetailViewController.channelKeyID = self.channelKey; groupDetailViewController.alChatViewController = self; [self.navigationController pushViewController:groupDetailViewController animated:YES];
任何帮助都将受到欢迎。提前致谢。
解决
在查看了所有可能的解决方案之后,我尝试更改模拟器,并且它运行良好,并且我编写了代码,就像我们通常按照以下步骤操作一样:
let storyboard = UIStoryboard(name: "WodPodMain", bundle: Bundle(for: AdditionVC.self)) if let vc = storyboard.instantiateViewController(withIdentifier: "AdditionVC") as? AdditionVC{ self.navigationController?.pushViewController(vc,animated: true) }
所以这个问题很奇怪,模拟器有一些问题!