ios - inserting row into a tableview from viewdidload -
i have uiviewcontroller tableview in it. im trying query through users in firebase data base keep getting error:
'nsinternalinconsistencyexception', reason: 'attempt insert row 1 section 0, there 0 rows in section 0 after update'
i looked , tried beginupdates , endupdates methods same error on line call endupdates. ideas why happening?
heres code:
searchcontroller.searchresultsupdater = self searchcontroller.dimsbackgroundduringpresentation = false searchcontroller.definespresentationcontext = true definespresentationcontext = true self.browsetable.tableheaderview = searchcontroller.searchbar ref.child("users").queryordered(bychild: "name").observe(.childadded, with: { (snapshot) in self.usersarray.append(snapshot.value as? nsdictionary) //insert rows //self.browsetable.beginupdates() //where error occurs self.browsetable.insertrows(at: [indexpath(row:self.usersarray.count - 1,section: 0)], with: .automatic) //self.browsetable.endupdates() }) { (error) in print("error: \(error.localizeddescription)") }
as discussed in comments regarding problem, crash caused due value returned in function func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int
not matching number of rows after inserting rows.
in cases value returned in numberofrowsinsection
function based on datasource object, updating datasource object before inserting/deleting rows resolve problem.
feel free suggest edits :)
Comments
Post a Comment