我的情况:
有一个叫做friendCardList声明的数组AppDelegate.swift,而且CardModel只是普通的类:
var friendCardList:[CardModel] = []
Run Code Online (Sandbox Code Playgroud)
在UITableViewController调用中FriendListVC,数组中的元素friendCardList将列在FriendListVC:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let card = delegate.exchangeListCards[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier("CardsCell",
forIndexPath: indexPath) as! BrowserTableViewCell
return cell
}
Run Code Online (Sandbox Code Playgroud)
我试图删除以下单元格FriendListVC:
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let card = delegate.exchangeListCards[indexPath.row]
var CardSet = NSMutableSet(array: delegate.exchangeListCards)
CardSet.removeObject(card)
delegate.exchangeListCards = CardSet.allObjects as! [CardModel]
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
当我通过向左滑动单元格来删除单元格时,编译器抛出了错误:
fatal error: Array index out of range
Run Code Online (Sandbox Code Playgroud)

我整个中午都在这里封锁了.
你需要打电话
self.reloadData()
Run Code Online (Sandbox Code Playgroud)
每次修改数据源时,在UITableViewController中.
| 归档时间: |
|
| 查看次数: |
1950 次 |
| 最近记录: |