UITableViewCell超出界限但在调试中有界限

时间:2017-10-16 12:47:37

标签: ios swift uitableview

我在我的应用中为每一天创建了一个tableView部分。在模拟器中,当我从头开始添加数据时(tableview为空),它显示OK所有数据,该部分的名称是当天,一切正常但是当我从我的设置更改日期并添加新输入时出现错误当我创建单元格时,它已经超出界限。我设置了一些打印件,看它是否超出界限,似乎是在界限内,但我不知道为什么会出现这个错误

代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      guard let cell = tableView.dequeueReusableCell(withIdentifier: "expenseCell") as? ExpenseCell else { return UITableViewCell() }
      print("SECTION: \(daySections[indexPath.section].daySection)")
      print("ROWS: \(daySections[indexPath.section].contentCount)")
      let budget = userBudget[indexPath.section][indexPath.row] // <- error getting here
      cell.delegate = self
      cell.configureCell(budget: budget)
      return cell
  }


func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return UITableViewCellEditingStyle.none
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return  Int(daySections[section].contentCount)
}

func numberOfSections(in tableView: UITableView) -> Int {
    return daySections.count
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return daySections[section].daySection
}  

调试:

SECTION: Optional("21.10.2017")
ROWS: 2
SECTION: Optional("21.10.2017")
ROWS: 2
SECTION: Optional("22.10.2017")
ROWS: 1
fatal error: Index out of range
2017-10-16 15:41:30.284173+0300 Expense Manager[7877:380262] fatal error: Index out of range
(lldb) 

我还设置了打印件以显示indexPath.sectionindexPath.row,当我收到错误时,它们是部分:1;行:0。

0 个答案:

没有答案
相关问题