使用纸质入职时出错

时间:2017-07-09 17:12:45

标签: ios swift

我一直在Youtube上关注本教程:https://www.youtube.com/watch?v=G5UkS4Mrepo但是我在返回时不断收到以下错误,无法找到解决方案:

  

无法将类型'(String,String,String,String,UIColor,UIColor,UIColor,UIFont,UIFont)'的返回表达式转换为返回类型'OnboardingItemInfo'(又名'(imageName:UiImage,title:String,description: String,iconName:UiImage,color:UIColor,titleColor:UIColor,descriptionColor:UIColor,titleFont:UIFont,descriptionFont:UIFont)')

在15:13分左右,他根据他提供的代码显示了一个正常运行的应用程序,但我的错误正在发生。这是我的代码:

...

@IBOutlet weak var onboardingView: OnboardingView!

override func viewDidLoad() {
    super.viewDidLoad()
    onboardingView.dataSource = self
}

func onboardingItemsCount() -> Int {
    return 3
}

func onboardingItemAtIndex(_ index: Int) -> OnboardingItemInfo {
    let backgroundColorOne = UIColor(red: 217/255, green: 72/255, blue: 89/255, alpha: 1)
    let backgroundColorTwo = UIColor(red: 106/255, green: 166/255, blue: 211/255, alpha: 1)
    let backgroundColorThree = UIColor(red: 168/255, green: 200/255, blue: 78/255, alpha: 1)

    return[
        ("rocket", "a great rocket start", "text description", "", backgroundColorOne, UIColor.white, UIColor.white, titleFont, descriptionFont)
    ][index]
}

...

在此处找到文档:https://cdn.rawgit.com/Ramotion/paper-onboarding/master/docs/index.html

2 个答案:

答案 0 :(得分:2)

根据错误消息,返回的元组中的第1个和第4个值需要UIImage类型,而不是String。曾经设计过这个API的人在这两个值的命名约定方面表现不佳。

另请注意,您已指定有3个项目,但onboardingItemAtIndex只有一个值的数组。

答案 1 :(得分:1)

尝试此代码

    let rocket  = UIImage(named: "rocket") as UIImage!  // implicitly unwrapped

    return [
        OnboardingItemInfo(informationImage: rocket!,
                           title: "title",
                           description: "description",
                           pageIcon: rocket!,
                           color: UIColor(red: 168/255, green: 200/255, blue: 78/255, alpha: 1),
                           titleColor: UIColor.white,
                           descriptionColor: UIColor.white,
                           titleFont: UIFont(name: "AvenirNext-Bold", size: 24)!,
                           descriptionFont: UIFont(name: "AvenirNext-Regular", size: 18)!),
        ][index]