Motivo NSInvalidArgumentException: 'Storyboard non contiene un controller di visualizzazione con identificatore' CenterViewController ''

Errore: imansible istanziare il controller di visualizzazione predefinito per UIMainStoryboardFile 'Main' – forse il punto di ingresso designato non è impostato?

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x7ff949770c30>) doesn't contain a view controller with identifier 'CenterViewController'' 

Non so cosa c'è di sbagliato nel mio Main Storyboard. Stavo costruendo il mio pannello di navigazione.

CenterViewController.swift

 import UIKit @objc protocol CenterViewControllerDelegate { optional func toggleLeftPanel() optional func collapseSidePanels() } class CenterViewController: UIViewController, SideMenuPanelViewControllerDelegate { //@IBOutlet weak private var testimageView: UIImageView! @IBOutlet weak private var testLabel:UILabel! var delegate: CenterViewControllerDelegate? // MARK: Button actions @IBAction func MenuTapped(sender: AnyObject) { delegate?.toggleLeftPanel?() } func localSelected(local: LocalMenus) { //imageView.image = animal.image testLabel.text = local.title delegate?.collapseSidePanels?() } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ 

}

ContainerViewController.swift

 import UIKit import QuartzCore enum SideOutState { case BothCollapsed case LeftPanelExpanded case RightPanelExpanded } class ContainerViewController: UIViewController, CenterViewControllerDelegate, UIGestureReceachzerDelegate{ var centerNavigationController: UINavigationController! var centerViewController: CenterViewController! var currentState: SideOutState = .BothCollapsed { didSet { let shouldShowShadow = currentState != .BothCollapsed showShadowForCenterViewController(shouldShowShadow) } } var leftMenuController: SideMenuPanelViewController? let centerPanelExpandedOffset: CGFloat = 60 override func viewDidLoad() { super.viewDidLoad() centerViewController = UIStoryboard.centerViewController() centerViewController.delegate = self // wrap the centerViewController in a navigation controller, so we can push views to it // and display bar button items in the navigation bar centerNavigationController = UINavigationController(rootViewController: centerViewController) view.addSubview(centerNavigationController.view) addChildViewController(centerNavigationController) centerNavigationController.didMoveToParentViewController(self) let panGestureReceachzer = UIPanGestureReceachzer(target: self, action: "handlePanGesture:") centerNavigationController.view.addGestureReceachzer(panGestureReceachzer) } // MARK: CenterViewController delegate methods func toggleLeftPanel() { let notAlreadyExpanded = (currentState != .LeftPanelExpanded) if notAlreadyExpanded { addLeftPanelViewController() } animateLeftPanel(shouldExpand: notAlreadyExpanded) } func collapseSidePanels() { switch (currentState) { case .LeftPanelExpanded: toggleLeftPanel() default: break } } func addLeftPanelViewController() { if (leftMenuController == nil) { leftMenuController = UIStoryboard.leftMenuController() leftMenuController!.local = LocalMenus.allLocal() addChildSidePanelController(leftMenuController!) } } func addChildSidePanelController(sidePanelController:SideMenuPanelViewController) { sidePanelController.delegate = centerViewController view.insertSubview(sidePanelController.view, atIndex: 0) addChildViewController(sidePanelController) sidePanelController.didMoveToParentViewController(self) } func animateLeftPanel(#shouldExpand: Bool) { if (shouldExpand) { currentState = .LeftPanelExpanded animateCenterPanelXPosition(targetPosition: CGRectGetWidth(centerNavigationController.view.frame) - centerPanelExpandedOffset) } else { animateCenterPanelXPosition(targetPosition: 0) { finished in self.currentState = .BothCollapsed self.leftMenuController!.view.removeFromSuperview() self.leftMenuController = nil; } } } func animateCenterPanelXPosition(#targetPosition: CGFloat, completion: ((Bool) -> Void)! = nil) { UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: { self.centerNavigationController.view.frame.origin.x = targetPosition }, completion: completion) } func showShadowForCenterViewController(shouldShowShadow: Bool) { if (shouldShowShadow) { centerNavigationController.view.layer.shadowOpacity = 0.8 } else { centerNavigationController.view.layer.shadowOpacity = 0.0 } } // MARK: Gesture receachzer func handlePanGesture(receachzer: UIPanGestureReceachzer) { // we can determine whether the user is revealing the left or right // panel by looking at the velocity of the gesture let gestureIsDraggingFromLeftToRight = (receachzer.velocityInView(view).x > 0) switch(receachzer.state) { case .Began: if (currentState == .BothCollapsed) { // If the user starts panning, and neither panel is visible // then show the correct panel based on the pan direction if (gestureIsDraggingFromLeftToRight) { addLeftPanelViewController() } showShadowForCenterViewController(true) } case .Changed: // If the user is already panning, translate the center view controller's // view by the amount that the user has panned receachzer.view!.center.x = receachzer.view!.center.x + receachzer.translationInView(view).x receachzer.setTranslation(CGPointZero, inView: view) case .Ended: // When the pan ends, check whether the left or right view controller is visible if (leftMenuController != nil) { // animate the side panel open or closed based on whether the view has moved more or less than halfway let hasMovedGreaterThanHalfway = receachzer.view!.center.x > view.bounds.size.width animateLeftPanel(shouldExpand: hasMovedGreaterThanHalfway) } default: break } } 

}

 private extension UIStoryboard { class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) } class func leftMenuController() -> SideMenuPanelViewController? { return mainStoryboard().instantiateViewControllerWithIdentifier("SideMenuPanelViewController") as? SideMenuPanelViewController } class func centerViewController() -> CenterViewController? { return mainStoryboard().instantiateViewControllerWithIdentifier("CenterViewController") as? CenterViewController } } 

Solutions Collecting From Web of "Motivo NSInvalidArgumentException: 'Storyboard non contiene un controller di visualizzazione con identificatore' CenterViewController ''"

Molto semplice.

Nel tuo storyboard principale, non hai ViewController con ID storyboard "CenterViewController"

Guarda qui: https://stackoverflow.com/a/11604827/3324388

Risposta breve da Xcode 8.0 in poi,

Vai a Main.storyboard seleziona il Main.storyboard target, premi Command+option+3 per visualizzare gli attributi

  • Riempi il field di inserimento StoryBoard ID
  • Seleziona la casella di controllo Use Storyboard ID

inserisci la descrizione dell'immagine qui

So che questo potrebbe essere trovato sulla risposta di riferimento duplicata, ma è necessario leggere, provare, errore ecc.