【问题标题】:Swift: XLPagerTabStrip: ButtonBarPagerTabStripViewController: ChildViewController IBOutlets are not setSwift: XLPagerTabStrip: ButtonBarPagerTabStripViewController: ChildViewController IBOutlets 未设置
【发布时间】:2018-08-09 11:11:01
【问题描述】:

Xcode -> 9.4.1,iOS -> 11.4,XLPagerTabStrip -> 8.0.1

我想使用 swift 在 ios 中创建顶部滚动标签(就像在 android 中一样)。

我正在使用库 XLPagerTabStrip 中的 ButtonBarPagerTabStripViewController。下面是代码:-

class ParentViewController: ButtonBarPagerTabStripViewController {

    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {

        return [ChildOneViewController(), ChildTwoViewController(), ChildThreeViewController()]

    }

}

现在一切正常,为三个 childviewcontrollers 创建了三个滚动选项卡,在左右滑动时会发生变化。但是当我在情节提要中为第一个 childviewcontroller 创建一个标签并在 ChildOneViewController 类中为此标签创建一个 IBOutlet 时。 此标签未设置,并且在 viewdidload 中打印 nil,viewdidappear。代码是这样的:-

class ChildOneViewController: UIViewController, IndicatorInfoProvider {

    @IBOutlet weak var label: UILabel!   // This label i have set from storyboard.

    func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {

        return IndicatorInfo(title: "CHILD ONE")

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        print(self.label) // This is printing nil to console.

   }

   override func viewDidAppear(_ animated: Bool) {
       super.viewDidAppear(animated)

       print(self.label) // This is also printing nil to console.

   }

}

【问题讨论】:

    标签: ios swift xlpagertabstrip


    【解决方案1】:

    如果 vcs 是在 IB 中创建的,那么不要使用

    ChildOneViewController()
    

    但使用

    let ch1 = self.storyboard?.instantiateViewController(withIdentifier: "childOneId") as! ChildOneViewController
    

    给每个人一个标识符并像上面一样加载它

    【讨论】:

    • 挣扎了几个小时。谢谢,这是一件很明显的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多