A solution for preventing the last item displaying "No more items!" from being selected


#1

After connecting segue which opens the details view, when user touches the last item displaying “No more items!”, the app crashes!

override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
var indexPath = indexPath
if indexPath.row == itemStore.allItems.count {
// Prevent the last row displaying “No more items!” from being selected.
indexPath.row = -1
}

    return indexPath
}