Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 致命错误:数组索引超出范围_Ios_Arrays_Swift - Fatal编程技术网

Ios 致命错误:数组索引超出范围

Ios 致命错误:数组索引超出范围,ios,arrays,swift,Ios,Arrays,Swift,我的情况: AppDelegate.swift中声明了一个名为friendCardList的数组,CardModel只是普通类: var friendCardList:[CardModel] = [] 在名为FriendListVC的UITableViewController中,friendCardList数组中的元素将列在FriendListVC中: 我试图删除FriendListVC中的单元格: 我的问题是: 当我通过向左滑动单元格删除单元格时,编译器抛出了错误: fatal error:

我的情况:

AppDelegate.swift中声明了一个名为friendCardList的数组,CardModel只是普通类:

var friendCardList:[CardModel] = []
在名为FriendListVC的UITableViewController中,friendCardList数组中的元素将列在FriendListVC中:

我试图删除FriendListVC中的单元格:

我的问题是:

当我通过向左滑动单元格删除单元格时,编译器抛出了错误:

fatal error: Array index out of range
我整个中午都在这里堵车。

你需要打电话

self.reloadData()

每次修改数据源时,都会在UITableViewController中删除数据。

提示:您已从数组中删除了数据,但tableview不知道这一点。您需要将数据集更改通知tableview@MidhunMP我正在处理一个类似的错误,如何将更改通知tableview?我在代码中使用了self.reloadData,非常感谢。当我添加self.reloadData时,Bug消失了。@EthanJoe:我不推荐这样做。重新加载整个tableview不是一个好做法。您可以改为使用DeleteRowatineXpath方法。检查本教程
fatal error: Array index out of range
self.reloadData()