我是Swift的新手,我使用ObjectMapper
解析我的JSON,但我希望数据显示在TableView中。但我有一个问题:
libc ++ abi.dylib:以NSException类型的未捕获异常终止
我在方法numberOfRowsInSection
之后得到它。我的数组不是nil,数组有2193个元素
我不明白为什么会发生
我的解析JSON的代码:
let timeStamp = NSNumber(value: Date().timeIntervalSinceNow)
var programs = [PrograToDayModel]()
override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
let timeStamp = NSNumber(value: Date().timeIntervalSinceNow)
self.downloadPrograms(for: timeStamp)
}
func downloadPrograms(for timestamp: NSNumber) {
Alamofire.request("http://52.50.138.211:8080/ChanelAPI/programs/\(timestamp)").responseArray { (response: DataResponse<[PrograToDayModel]>) in
let programlArray = response.result.value
if let programlArray = programlArray {
for program in programlArray {
self.programs.append(program)
print(program.title as Any)
}
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
我的表格代码:
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
print(self.programs.count as Any)
return self.programs.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProgramTableViewCell", for: indexPath) as! ProgramTableViewCell
cell.title.text = self.programs[indexPath.row].title
return cell
}
}
所有标识符到位 我使用tab bar,tableView,tableViewCell 我怎么解决这个问题?
答案 0 :(得分:3)
答案 1 :(得分:0)
尝试添加部分/行数时尝试初始化uitableviewcontroller
时,我收到类似的非描述性错误。你注册了tableview单元类吗?我看到你创建了一个自定义的tableview单元格,所以如果没有在你的tableview中注册那可能导致这个错误。
tableView.register("ProgramTableViewCell".self, forCellReuseIdentifier: "ProgramTableViewCell")