【发布时间】:2019-03-01 05:14:54
【问题描述】:
我有一个名为 HomeController() 的主视图控制器。有一个包含三个部分的分组表视图。第一部分应该显示我的 JSON 文件中的数据。为了给出一个想法,我想在我的第一部分显示电视剧季的列表,例如第 1 季、第 2 季、第 3 季。
如果用户点击第 1 季,将推送一个新的视图控制器,其中包含一个表格视图,其中行显示第 1 季剧集的标题。如果用户点击剧集,则会再次推送一个新的 VC,它将在 UILabel 中显示剧集标题并在文本视图中显示剧集摘要。
目前我正在传递如下静态数据
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let destVC = EpisodeTextController()
if indexPath.row == 0 {
destVC.episodeTitleLabel.text = "Minimum Viable product"
destVC.textView.text = "Basic text"
}
self.navigationController?.pushViewController(destVC, animated: true)
}
这是我的基本 JSON 文件
{
"Seasons": [
{
"Season Name": "season1",
"Season Desccription": "season description",
"Episodes": [
{
"title": "title of episode1",
"desc": "description of episode1"
},
{
"title": "title of episode2",
"desc": "description of episode2"
}
]
},
{
"Season Name": "Season 2",
"Season Desccription": "season description",
"Episodes": [
{
"title": "title of episode1",
"desc": "description of episode1"
},
{
"title": "ttile of episode2",
"desc": "description of episode2"
},
{
"title": "episode3",
"desc": "description"
}
]
}
]
}
这是我的模型对象
struct Show: Codable {
let seasons: String
let episodes: [String]
let episodeTitle: String
let episodeSummary: String
}
我不知道这是对还是错
【问题讨论】:
-
社区将随时关闭此问题,因为它没有显示任何尝试/研究。编辑您的问题并显示到目前为止您拥有的代码,解释它的问题是什么,并且该问题将被更好地接受并且可能会得到有用的答案
-
为什么要传递 JSON?假设您已经对其进行了解码,那么为什么不直接传递对象的不同部分呢?在我看来,您有 2 个数组(UITableViewController 的数据源)和一个可以在普通 UIViewController 上使用的元素。真的需要看看你做了什么,
标签: ios json swift uitableview swift4