2014-11-17 4 views
1

THIS 튜토리얼을 따르고 있습니다.하지만 다르게 만들고 싶기 때문에이 튜토리얼의 스타터 프로젝트 파일을 다운로드하지 않았습니다. 이 오류가 있습니다 :'UIStoryboard.type'에 'centerViewController'라는 멤버가 없습니다

'UIStoryboard.type' does not have member named 'centerViewController' 

여기 ContainerViewController에 subView (CenterViewController)를 추가하려고합니다. 여기

이 내 CenterViewController.swift

import UIKit 

@objc 
protocol CenterViewControllerDelegate { 
optional func toggleLeftPanel() 
optional func collapseSidePanels() 
} 

class CenterViewController: UIViewController { 

var delegate: CenterViewControllerDelegate? 

@IBAction func tableTapped(sender: AnyObject) { 

    } 
} 

입니다 ContainerViewController.swift

import UIKit 
import QuartzCore 

class ContainerViewController: UIViewController, CenterViewControllerDelegate { 

var centerNavigationController: UINavigationController! 
var centerViewController: CenterViewController! 


override init() { 
    super.init(nibName: nil, bundle: nil) 
} 

required init(coder aDecoder: NSCoder) { 
    super.init(coder: aDecoder) 
} 


override func viewDidLoad() { 
    super.viewDidLoad() 

    centerViewController = UIStoryboard.centerViewController()  
    //'UIStoryboard.type' does not have member named '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) 

    } 

} 

내 코드입니다 그리고 이것은 내 AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    window = UIWindow(frame: UIScreen.mainScreen().bounds) 

    let containerViewController = ContainerViewController() 

    window!.rootViewController = containerViewController 
    window!.makeKeyAndVisible() 
    return true 
} 
,536입니다

anyOne은 내가 누락 된 아이디어를 알려줄 수 있습니까?

답변

2

UIStoryboard.centerViewController() 메서드를 만드는 자습서 작성자가 제공 한 확장 기능이 없습니다. 코드는 자신의 다운로드 스타터 프로젝트 ContainerViewController.swift의 하단에, 나는뿐만 아니라 아래로 아래로 복사 한 :

private extension UIStoryboard { 
    class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) } 

    class func leftViewController() -> SidePanelViewController? { 
    return mainStoryboard().instantiateViewControllerWithIdentifier("LeftViewController") as? SidePanelViewController 
    } 

    class func rightViewController() -> SidePanelViewController? { 
    return mainStoryboard().instantiateViewControllerWithIdentifier("RightViewController") as? SidePanelViewController 
    } 

    class func centerViewController() -> CenterViewController? { 
    return mainStoryboard().instantiateViewControllerWithIdentifier("CenterViewController") as? CenterViewController 
    } 
} 

이 ContainerViewController.swift의 바닥에 이것을 추가하고 작동합니다. 즉, 올바른 뷰어 컨트롤러에서 올바른 식별자를 사용하여 오른쪽 스토리 보드 파일을 설정하면됩니다.

+0

감사합니다. 도움이되었습니다. 도움에 감사드립니다. –

+0

View Controller 클래스를 호출 할 때 작동하지 않습니다. 오류는 -> "메서드는 결과가 내부 형식을 사용하기 때문에 내부적으로 선언되어야합니다". 어떤 생각? – Megamind

+0

@Megamind 당신은 아마도 당신의 코드를 포함하여 완전히 새로운 질문을함으로써 가장 잘 봉사하게 될 것입니다. 컨텍스트가 없으면 문제가 해결되지 않습니다. –