iOS:EXC_BAD_指令(代码=EXC_I386_INVOP)刷新tableview时出错

iOS:EXC_BAD_指令(代码=EXC_I386_INVOP)刷新tableview时出错,ios,swift,xcode,uitableview,Ios,Swift,Xcode,Uitableview,我正在为我的tableview页面创建一个拉入刷新功能。刷新步骤如下所示: 调用API并从internet获取数据 使用数据创建另一个呼叫 使用步骤2中的数据,使用tableview.reloadData() 当拉动刷新时,它有时会工作,但有时会崩溃,控制台中的错误消息致命错误:索引超出范围,以及EXC\u BAD\u指令(code=EXC\u I386\u INVOP,subcode=0x0)消息标记在if代码块上。我不知道是什么错误 这是error显示的函数 override func ta

我正在为我的tableview页面创建一个拉入刷新功能。刷新步骤如下所示:

  • 调用API并从internet获取数据
  • 使用数据创建另一个呼叫
  • 使用步骤2中的数据,使用
    tableview.reloadData()
  • 当拉动刷新时,它有时会工作,但有时会崩溃,控制台中的错误消息
    致命错误:索引超出范围
    ,以及
    EXC\u BAD\u指令(code=EXC\u I386\u INVOP,subcode=0x0)
    消息标记在
    if
    代码块上。我不知道是什么错误

    这是error显示的函数

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
        if feedList[indexPath.row].type == "announcement" {
            let cell = feedTable.dequeueReusableCell(withIdentifier: "announcementCell") as! FeedCell
            cell.subjectLbl.text = "Announcement - "+feedList[indexPath.row].courseName
            cell.titleLbl.text = feedList[indexPath.row].title
            cell.dateLbl.text = "Posted on "+feedList[indexPath.row].date
            cell.courseImg.sd_setImage(with: feedList[indexPath.row].imgSrc)
            return cell
        }
        else if feedList[indexPath.row].type == "assignment" {
            let cell = feedTable.dequeueReusableCell(withIdentifier: "assignmentCell") as! FeedCell
            cell.subjectLbl.text = "Assignment - "+feedList[indexPath.row].courseName
            cell.titleLbl.text = feedList[indexPath.row].title
            cell.dateLbl.text = "Due date "+feedList[indexPath.row].dueDate!
            cell.courseImg.sd_setImage(with: feedList[indexPath.row].imgSrc)
            return cell
        }
        else {
            let cell = feedTable.dequeueReusableCell(withIdentifier: "materialCell") as! FeedCell
            cell.subjectLbl.text = "Material - "+feedList[indexPath.row].courseName
            cell.titleLbl.text = feedList[indexPath.row].title
            cell.dateLbl.text = "Posted on "+feedList[indexPath.row].date
            cell.courseImg.sd_setImage(with: feedList[indexPath.row].imgSrc)
            return cell
        }
    }
    
    注:

    SDWebImage
    已安装库

    FeedCell
    是从
    UITableViewCell

    feedList
    结构类似于这样的
    [(类型:String,courseName:String,imgSrc:URL,title:String,date:String,dueDate:String?)


    cell.subjectLbl
    cell.titleBL
    cell.dateLbl
    cell.courseImg
    FeedCell

    中的出口,请查看您的数据源。您正在尝试访问不在数组中的数组元素。示例数组包含5个元素,您尝试访问7个元素看看您的数据源。您正在尝试访问不在数组中的数组元素。示例数组包含5个元素,您尝试访问7个元素