使用板载

时间:2015-12-14 21:51:07

标签: swift uiviewcontroller

嘿伙计们,我现在正在使用板载库,如果您不知道它https://github.com/mamaral/Onboard

问题在于我试图在我的视图控制器中而不是在app委托中使用它,如示例中所示,使用以下代码来设置视图控制器。

self.window.rootViewController = self.generateSecondDemoVC()

但我似乎无法在我的视图控制器中执行此操作,因为没有选项可以编译,我怎样才能将视图控制器设置为返回OnboardingViewController的方法?

这是我的视图控制器文件

//
//  PurchaseViewController.swift
//  News Cartel
//
//  Created by Tunde Adegoroye on 13/12/2015.
//  Copyright © 2015 Tunde Adegoroye. All rights reserved.
//

import UIKit
import Onboard

class PurchaseViewController: OnboardingViewController {

    @IBAction func closeButtonDidTouch(sender: AnyObject) {
        dismissViewControllerAnimated(true, completion: nil)
    }

    func loadFromNewFilters(notification: NSNotification){


    }

    override func viewDidAppear(animated: Bool) {

        // Can't seem to hook it upto the viewcontroller here
        generatePurchasePaging()

    }


    func generatePurchasePaging() -> OnboardingViewController {

        let welcomePage = OnboardingContentViewController(title: "PAY WHAT YOU WANT", body: "I made my app so you could have the best experience reading tech related news. That’s why I want you to value it based on your satisfaction.", image: UIImage(named: "Purchase-Pig"), buttonText: "") { () -> Void in

        }

        let firstPurchasePage = OnboardingContentViewController(title: "MINT", body: "The app is great but there’s still a few places in room of improvement. If this is your feeling this is for you.", image: UIImage(named: "Purchase-Mint"), buttonText: "69p") { () -> Void in

        }

        let secondPurchasePage = OnboardingContentViewController(title: "SWEET", body: "IThis is the suggested price where you value the time I spent on development and design. Feel free to pay more or less.", image: UIImage(named: "Purchase-Lolly"), buttonText: "£1.49") { () -> Void in

        }

        let thirdPurchasePage = OnboardingContentViewController(title: "GOLD", body: "Hello is it me your looking for, if this popped into your mind using the app then this is the price for you.", image: UIImage(named: "Purchase-Gold"), buttonText: "£2.99") { () -> Void in

        }

        let purchaseVC = OnboardingViewController(backgroundImage: nil, contents: [welcomePage, firstPurchasePage, secondPurchasePage, thirdPurchasePage])

        return purchaseVC
    }
}

2 个答案:

答案 0 :(得分:2)

我希望这就是你想要的

class ViewController: OnboardingViewController {

  override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
     super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  }

  required init?(coder aDecoder: NSCoder) {

     let welcomePage = OnboardingContentViewController(title: "PAY WHAT YOU WANT", body: "I made my app so you could have the best experience reading tech related news. That’s why I want you to value it based on your satisfaction.", image: UIImage(named: "Purchase-Pig"), buttonText: "") {}
     let firstPurchasePage = OnboardingContentViewController(title: "MINT", body: "The app is great but there’s still a few places in room of improvement. If this is your feeling this is for you.", image: UIImage(named: "Purchase-Mint"), buttonText: "69p") {}
     let secondPurchasePage = OnboardingContentViewController(title: "SWEET", body: "IThis is the suggested price where you value the time I spent on development and design. Feel free to pay more or less.", image: UIImage(named: "Purchase-Lolly"), buttonText: "£1.49") {}
     let thirdPurchasePage = OnboardingContentViewController(title: "GOLD", body: "Hello is it me your looking for, if this popped into your mind using the app then this is the price for you.", image: UIImage(named: "Purchase-Gold"), buttonText: "£2.99") {}

     super.init(backgroundImage: nil, contents: [welcomePage, firstPurchasePage, secondPurchasePage, thirdPurchasePage])

     // Customize Onboard viewController
     allowSkipping = true
     skipHandler = { print("Skip") }

  }

  override func viewDidLoad() {
     super.viewDidLoad()
     view.backgroundColor = UIColor.yellowColor()
  }

}

Github上的演示

答案 1 :(得分:2)

我通过添加此

来解决这个问题
override func viewWillAppear(animated: Bool) {

    self.view.addSubview(generatePurchasePaging().view)
}