问题是:我不知道如何说我的UITableViewController每个帖子都是单独的,当单击该帖子时,会打开一个新的UIViewController并显示相应帖子的内容
到目前为止,我已经尝试在Main.storyboard中创建一个新的UIViewController。但是,我不知道如何继续。
这是我以前的代码:
override func viewDidLoad() {
super.viewDidLoad()
fetchJSON()
}
struct Course: Codable {
let title: Title
let content, excerpt: Content
let links: Links
enum CodingKeys: String, CodingKey {
case title, content, excerpt
case links = "_links"
}
}
struct Content: Codable {
let rendered: String
let protected: Bool
}
struct Links: Codable {
}
struct Title: Codable {
let rendered: String
}
fileprivate func fetchJSON() {
let urlString = "Example URL"
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, _, err) in
DispatchQueue.main.async {
if let err = err {
print("Failed to get data from url:", err)
return
}
guard let data = data else { return }
do {
self.courses = try JSONDecoder().decode([Course].self, from: data)
self.tableView.reloadData()
} catch let jsonErr {
print("Failed to decode:", jsonErr)
}
}
}.resume()
}
我有一个UIViewController,我希望如果您单击一个UITableViewCell,则相应的帖子将出现在UITableView中