2017-05-24 38 views
1

我正在使用類似於android的選項卡iOSSwift3。我已經安裝XLPagerTabStrip成功的,但面臨的問題: -iOS中的Android選項卡Swift

終止應用程序由於未捕獲的異常 「NSInvalidArgumentException」的,原因是:「故事板()不包含具有標識符 視圖控制器‘child1’

這裏是我的代碼: -

import UIKit 
import XLPagerTabStrip 
class ParentViewController: ButtonBarPagerTabStripViewController { 

let customPurpleColor = UIColor(red:0.13 , green : 0.03 , blue : 0.25 , alpha : 1.0) 
override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view. 
    settings.style.buttonBarBackgroundColor = .white 
    settings.style.buttonBarItemBackgroundColor = .white 
    settings.style.selectedBarBackgroundColor = customPurpleColor 
    settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14) 
    settings.style.selectedBarHeight = 1.0 
    settings.style.buttonBarMinimumLineSpacing = 0 
    settings.style.buttonBarItemTitleColor = .black 
    settings.style.buttonBarItemsShouldFillAvailiableWidth = true 
    settings.style.buttonBarLeftContentInset = 0 
    settings.style.buttonBarRightContentInset = 0 
    changeCurrentIndexProgressive = { [weak self] (oldCell : ButtonBarViewCell? , newCell : ButtonBarViewCell? 
     , progressPercentage: CGFloat, changeCurrentIndex : Bool , animated : Bool) -> Void in 
     guard changeCurrentIndex == true else {return} 
     oldCell?.label.textColor = .black 
     newCell?.label.textColor = self?.customPurpleColor 
     } 
} 
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { 
    let child_1 = UIStoryboard(name : "Main" , bundle : nil).instantiateViewController(withIdentifier: "child1") 
    let child_2 = UIStoryboard(name : "Main" , bundle : nil).instantiateViewController(withIdentifier: "child2") 
    return [child_1 , child_2] 
     } 
} 

ChildViewController1.swift: -

import UIKit 
import XLPagerTabStrip 


class ChildViewController1: UIViewController , IndicatorInfoProvider{ 
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo { 
    return IndicatorInfo(title : "child1") 
} 
} 

ChildViewController2.swift: -

import UIKit 
import XLPagerTabStrip 

class ChildViewController2: UIViewController , IndicatorInfoProvider{ 
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo { 
    return IndicatorInfo(title : "child1") 
} 
} 

我在Main.storyboard使用UIScrollViewcollectionView到buttonBarView。因爲我是iOS開發新手,所以我不明白爲什麼會出現此錯誤?

+0

請不要使用 – Selvin

+1

需要在故事板設置視圖 - 控制標識符不與問題的相關標籤。 – KKRocks

回答

0

您需要設置視圖控制器的標識符如下:

enter image description here

+0

我將Storyboard ID設置爲child1,但它顯示相同的錯誤 –

+0

您的代碼在哪行中斷? – KKRocks

+0

故事板中的「child1」控制器是否真的名爲「Main」? –