我正在使用 swift 在 xCode 10.2 中工作。我在我的第一个视图控制器中为 6 个表视图创建了全局变量。在情节提要中,我有 6 tableViewControllers
。在一个单独的 swift 文件中,我创建了一个表结构来保存一个数组并显示每个相应单元格中的数据。在每个视图控制器中didSelectRowAt
连接下一个表视图。我的问题是当我到达最后一个表格视图时。我需要将网站 URL 关联到第五个表上的数组。我不断收到一条错误消息,指出无法将字符串转换为 URL。请帮忙!
var fifthArray = [
FifthTableStruct(FifthTitle: ["Energy Guide", "https://www.google.com", "Warranty Page", "Use & Care Guide", "Specification Sheet", "FIT System", "Installation Instructions"]),
FifthTableStruct(FifthTitle: ["Energy Guide", "Warranty Page", "Use & Care Guide", "Specification Sheet", "FIT System", "Installation Instructions"])
]
var sixthArray = [
SixthTableStruct(SixthTitle: ["https://www.whirlpool.com/content/dam/global/documents/201708/EnergyGuide-W11037203-RevA.pdf", "https://www.whirlpool.com/content/dam/global/documents/201708/WarrantyPage-W11037201-W.pdf", "https://www.whirlpool.com/content/dam/global/documents/201708/UseandCareGuide-W11037201-RevA.pdf", "https://www.whirlpool.com/content/dam/global/documents/201711/WL170160A_p2.pdf", "https://www.whirlpool.com/content/dam/global/documents/201901/wash-performance-guarantee-en.pdf", "https://www.whirlpool.com/content/dam/global/documents/201711/InstallationInstructions-W10682737-RevA.pdf"])
]
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let urlString = self.sixthArray[indexPath.row]
if let url = URL(fileURLWithPath: urlString)
{
UIApplication.shared.openURL(url)
}
}
我在与 viewController 分开的数组文件中有 tableStruct 的代码。
import Foundation
import UIKit
struct SecondTableStruct {
var SecondTitle = [String]()
}
struct ThirdTableStruct {
var ThirdTitle = [String]()
}
struct FourthTableStruct {
var FourthTitle = [String]()
}
struct FifthTableStruct {
var FifthTitle = [String]()
}
struct SixthTableStruct {
var SixthTitle = [String]()
}