2015-07-21 38 views
-1

我從雨燕1.2轉換項目2.下面的代碼:找不到接受所提供的參數「下標」超載 - 當轉換雨燕1.2至2

func pageControlChanged(pageControl: UIPageControl) { 
    // get the current and upcoming page numbers 
    let currentTutorialPage = (viewControllers[0] as! partyStepViewController).page 
    let upcomingTutorialPage = pageControl.currentPage 

    // what direction are we moving in? 
    let direction: UIPageViewControllerNavigationDirection = upcomingTutorialPage < currentTutorialPage ? .Reverse : .Forward 

    // set the new page, animated! 
    setViewControllers([partyStepForPage(upcomingTutorialPage)], 
     direction: direction, animated: true, completion: nil) 
} 

給我的以下錯誤:

Could not find an overload for 'subscript' that accepts the supplied arguments

對代碼的特定行:

let currentTutorialPage = (viewControllers[0] as! partyStepViewController).page 

這個錯誤是什麼消息呢?我該如何解決它?

這裏有一些鏈接到我的代碼:

回答

4

的問題是,viewControllersis now an Optional

所以,你必須解開它,然後才能下標是:viewControllers![0]

+0

你很聰明。你的答案幫助我感謝。 – Mariam

相關問題