所以这就是我正在做的事情。制作了一个带有不同“骑行”的表,“骑行单元”都链接到一个pageControllerView,但我希望它们链接到关于那个特定骑行的静态信息(var)。这意味着每次点击桌面视图RideCell都会链接到存储在网页浏览中的特定“游乐设施”信息,而不是通用页面视图......
错误在Ride2上,并说“无法转换”,我确信它与信息[Page]组件相关,代码行的末尾:
func setupRides() {
let ride2 = Ride(title: "Contacts", route: "", image: #imageLiteral(resourceName: "main"), info: [tron])
// let ride3 = Ride(title: "Pirates of the Caribbean", route: "Event", image: #imageLiteral(resourceName: "pirates"), info: [Page(title: "Pirates of the Caribbean", message: "Soaring Over the Horizon (FP)", imageName: "main")])
我只是试图让它在一个工作之前完成剩下的工作。
其他重要代码如下:
var tron: [Page] = {
let firstPage = Page(title: "Share a great listen", message: "It's free to send your books to the people in your life. Every recipient's first book is on us.", imageName: "main")
let secondPage = Page(title: "Send from your library", message: "Tap the More menu next to any book. Choose \"Send this Book\"", imageName: "main")
let thirdPage = Page(title: "Send from the player", message: "Tap the More menu in the upper corner. Choose \"Send this Book\"", imageName: "main")
return [firstPage, secondPage, thirdPage]
}()
这就是我的Ride和Page Classes的样子。
class Ride {
let title: String
let route: String
let image: UIImage
let info: [Page]
init(title: String, route: String, image: UIImage, info: [Page]){
self.title = title
self.route = route
self.image = image
self.info = info
}
}
class Page {
let title: String
let message: String
let imageName: String
init(title: String, message: String, imageName: String) {
self.title = title
self.message = message
self.imageName = imageName
}
}
很抱歉,如果这是Noob问题。我做了RTFF,但还没找到......
答案 0 :(得分:0)
tron
是Page
的数组,因为它被声明为[Page]
。
执行[tron]
时,您将tron
放在另一个数组中。您现在拥有[[Page]]
,这是Page
的数组数组。
如此简单:
let ride2 = Ride(title: "Contacts", route: "", image: #imageLiteral(resourceName: "main"), info: tron)