I have a table that basically loads data coming from backend i.e. Parse. Now after clicking on a cell and processing logic successfully on other view controller (detail controller), I have an unwind segue that is performed automatically. This unwind segue takes us back to the same table. Except when I go back, the same results showing in cells is showing twice (duplication). If I repeat the above process 3 times, I see each record duplicated 3 times and so on.
I read in other posts here that better clear the array, which I did but it seems its not working. Or it could be me clearing it in the wrong place.
Here is the code for viewWillAppear:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
SwiftAddressBook.requestAccessWithCompletion({ (success, error) -> Void in
if success {
if let people = swiftAddressBook?.allPeople {
let arrayOfArrays = people.flatMap({$0.phoneNumbers?.map( {$0.value})})
let finalArray = arrayOfArrays.flatMap({ $0 })
self.numbersArray = self.getCleanNumberArrayFromArrayInput(finalArray)
}
dispatch_async(dispatch_get_main_queue()) {
self.getUsersMatchingNumbers({ (result)->Void in
self.userMatchArray = []
self.userMatchArray = result
self.tableView.reloadData()
})
}
}
else {
//no success. Optionally evaluate error
print("Access Red")
}
})
}
and this is cellForRowAtIndex:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ContactTableCell
let row = indexPath.row
if(self.userMatchArray.count > 0 )
{
cell.name.text = self.userMatchArray[row]["name"] as? String
}else{
cell.name.text = "You have no friends yet"
}
return cell
}
Any help sorting this out would be appreciated. Thanks in advance.