我得到Json并将其传递到字符串数组中,然后将该字符串数组传递给表中的单元格,但我一直得到Thread 1:致命错误:索引超出范围,我的应用程序崩溃了。
var notificationsData = [NotificationsDataModel(headerName: "Today", subType: [NotificationsViewCell()], isExpandable: false), NotificationsDataModel(headerName: "Yesterday", subType: [NotificationsViewCell()], isExpandable: false), NotificationsDataModel(headerName: "Older", subType: [NotificationsViewCell()], isExpandable: false)]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if notificationsData[section].isExpandable {
return notificationsData[section].subType.count
}else {
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = notificationsTableView.dequeueReusableCell(withIdentifier: "notificationsIdentifier", for: indexPath) as! NotificationsViewCell
if notificationsData[indexPath.section].headerName == "Today" {
notificationsData[indexPath.section].subType[indexPath.row].todayNotificationPassangerName = todayNotificationPassangerNameArray[indexPath.row]
notificationsData[indexPath.section].subType[indexPath.row].todayNotificationMessage = todayNotificationMassageArray[indexPath.row]
cell.notificationCellImage.sd_setImage(with: URL(string: todayNotificationImageArray[indexPath.row]))
cell.notificationPassangerNameLabel.text = notificationsData[indexPath.section].subType[indexPath.row].todayNotificationPassangerName
cell.notificationMessageLabel.text = notificationsData[indexPath.section].subType[indexPath.row].todayNotificationMessage
return cell
}else if notificationsData[indexPath.section].headerName == "Yesterday" {
notificationsData[indexPath.section].subType[indexPath.row].yesterdayNotificationPassangerName = yesterdayNotificationPassangerNameArray[indexPath.row]
notificationsData[indexPath.section].subType[indexPath.row].yesterdayNotificationMessage = yesterdayNotificationMassageArray[indexPath.row]
cell.notificationCellImage.sd_setImage(with: URL(string: yesterdayNotificationImageArray[indexPath.row]))
cell.notificationPassangerNameLabel.text = notificationsData[indexPath.section].subType[indexPath.row].yesterdayNotificationPassangerName
cell.notificationMessageLabel.text = notificationsData[indexPath.section].subType[indexPath.row].yesterdayNotificationMessage
return cell
}else if notificationsData[indexPath.section].headerName == "Older" {
notificationsData[indexPath.section].subType[indexPath.row].olderNotificationPassangerName = olderNotificationPassangerNameArray[indexPath.row]
notificationsData[indexPath.section].subType[indexPath.row].olderNotificationMessage = olderNotificationMassageArray[indexPath.row]
cell.notificationCellImage.sd_setImage(with: URL(string: olderNotificationImageArray[indexPath.row]))
cell.notificationPassangerNameLabel.text = notificationsData[indexPath.section].subType[indexPath.row].olderNotificationPassangerName
cell.notificationMessageLabel.text = notificationsData[indexPath.section].subType[indexPath.row].olderNotificationMessage
return cell
}
return cell
}
我期望的结果是将数组传递给单元格以返回它