翠鸟 - 无法从网络

时间:2016-04-29 22:37:29

标签: ios swift

我有一系列网址,我正在尝试使用KingFisher加载到ImageView中。

arrPageTitle = ["This is The App Guruz", "This is Table Tennis 3D", "This is Hide Secrets"];
    arrPagePhoto = ["https://s3.amazonaws.com/fan-polls/heyward_again.jpg", "https://s3.amazonaws.com/fan-polls/Schwarber.jpg", "https://s3.amazonaws.com/fan-polls/mike_ditka.jpg"];

我正在尝试根据UIPageViewController的索引加载适当的图像:

pageContentViewController.imageView.kf_setImageWithURL((arrPagePhoto[index] as! String))

我收到了'致命错误:在解开可选值时意外发现nil

感谢任何帮助!

1 个答案:

答案 0 :(得分:2)

据我所知,kf_setImageWithURL需要NSURL,而不是String。

首先将arrPagePhoto[index]转换为NSURL,然后将其传递给kf_setImageWithURL

let downloadURL: NSURL = NSURL(string: arrPagePhoto[index])!

pageContentViewController.imageView.kf_setImageWithURL(downloadURL)