我的情況:致命錯誤:數組索引超出範圍
有一個稱爲friendCardList
要求中的AppDelegate.swift
陣列,並且所述CardModel
只是正常類:
var friendCardList:[CardModel] = []
在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
}
我試圖刪除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]
}
我的問題:
當我通過細胞向左滑動刪除單元格時,編譯器拋出的錯誤:
fatal error: Array index out of range
我堵住了這裏所有的中午。
提示:你從數組中刪除了數據,但是你的tableview並不知道。你需要通知你的tableview關於數據集的變化。 –
@MidhunMP我正在處理類似的錯誤,你如何通知tableview的變化?我在我的代碼 – SamYoungNY