嗨,這是我的代碼,我不斷收到錯誤,當我刪除一行。 我知道我的數組沒有被更新,因爲我刪除了一行,因此出現了錯誤。 Orerlist.list是一個數組獲取我的數據如何解決斷言失敗?
有多少我解決這個問題?
更新無效:部分0中的行數無效。更新(1)後現有部分中包含的行數必須等於更新前(1)部分中包含的行數,加上或減去從該部分插入或刪除的行數(0插入,1刪除),加上或減去移入或移出該部分的行數(0移入,0移出)。
class RootTableViewController: UITableViewController,MenuItemSelectionDelegate { var orderList = OrderList() var delegate:MenuItemSelectionDelegate! = nil
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return orderList.list.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = orderList.list[indexPath.row].menuItem
return cell
}
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
self.tableView.beginUpdates()
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
self.tableView.endUpdates()
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "reserve"{
let vc = segue.destinationViewController as! BeautyViewController
vc.delegate = self
}
}
func didSelectMenuItem(controller: UITableViewController, order: OrderModel) {
orderList.addList(order)
controller.navigationController?.popViewControllerAnimated(true)
tableView.reloadData()
}
}
#2是_not_的論壇。不要將[解決]添加到標題。 – dandan78