ipraba/EPContactsPicker

Crash when searching the contact and tapped Cancel

Closed this issue · 9 comments

Crash when searching the contact and tapped Cancel

yes it crashed!

bug confirmed.

if let contactsForSection = orderedContacts[sortedContactKeys[indexPath.section]] {
contact = EPContact(contact: contactsForSection[indexPath.row]) // crash is here
}
For example I have 6 contacts, but 2 of them in 1 section. When tap on cancel on search bar it recognizing as 5 contacts and crashing with error out of index

There is no issue when it's 1 section

I changede in EPContactPicker
public func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchBar.text = ""
dispatch_async(dispatch_get_main_queue(), {
//self.tableView.reloadData()
self.reloadContacts()
})
}

I tried it also it's still crash

I mark the line on func searchBarCancelButtonClicked
// searchBar.text = ""
it would not crash.

This not related to crash. Crash going from section & cell indexes

Because searchBar.text = "" will trigger func updateSearchResultsForSearchController ,
and it will call self.tableView.reloadData() , then trigger numberOfSectionsInTableView ,
in this case, resultSearchController.active is true , so section always return 1.

That didn't help anyway. It still crash