ios - Deleting Rows in UITableView Swift 3 -


okay im making app add items cart , updates add. adding fine, cant deleting work. in cart cell need remove 3 arrays, doesn't seem problem because keep getting error:

"terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid update: invalid number of rows in section 0. number of rows contained in existing section after update (1) must equal number of rows contained in section before update (1), plus or minus number of rows inserted or deleted section (0 inserted, 1 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out).'"

i'm not sure i'm doing wrong here. i've followed few tutorials , seem doing same thing. appreciated in advance.

heres of code:

//declaring arrays show in cell var cartkeys = [string]() var cartvalues = [string]()  var deets = [[string]]() var count = 0   //populating arrays original arrays  func populatecart(){      (key,value) in menustore.shared.cart {          self.cartkeys.append(key)         self.cartvalues.append(value)     }       in menustore.shared.cartanditems{         (k,v) in {             deets.append(v)         }     }      print("deets \(deets)")      c in cartview.visiblecells {          count += 1      }  }   func tableview(_ tableview: uitableview, commit editingstyle: uitableviewcelleditingstyle, forrowat indexpath: indexpath) {      switch tableview{      case cartview:         if editingstyle == .delete{             let index = indexpath.row             print(index)              cartkeys.remove(at: index)             cartvalues.remove(at: index)              deets.remove(at: index)               tableview.deleterows(at: [indexpath], with: .automatic)          }   func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     switch tableview{      case cartview:         let cartcell = tableview.dequeuereusablecell(withidentifier: "cartcell", for: indexpath) as? cartcell           cartcell?.carttitle.text = cartkeys[(indexpath nsindexpath).row]         cartcell?.cartprice.text = cartvalues[(indexpath nsindexpath).row]         cartcell?.cartdetails.text = deets[count].joined(separator: ", ")            return cartcell! 

ps. if wants replacing visible cells call thatd great. id loop through cells if not visible on screen.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -