I have a UITableView
as a subview of my UIScrollVIew
, which is the main view controlled by my MainViewController
.
In MainView
Maybe it is a typo after all. Check that your function is not didDeselectRowAtIndexPath:
(de select instead of select).
I was having this issue for a while, and I did not see any reference to it here, so for reference, another reason for this could be that:
tableView.editing = YES;
but
tableView.allowsSelectionDuringEditing = NO;
As per documentation for
- tableView:didSelectRowAtIndexPath:
This method isn’t called when the editing property of the table is set to YES (that is, the table view is in editing mode). See "Managing Selections" in Table View Programming Guide for iOS for further information (and code examples) related to this method.
Updated for Swift 3:
if you are used UITapGestureRecognizer in your code :- # Swift 3 use below lines of code:
extension YourViewController{
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(YourViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
tap.cancelsTouchesInView = false
}
func dismissKeyboard() {
view.endEditing(true)
}
}
How to called:- In ViewDidLoad()
self.hideKeyboardWhenTappedAround()
I had intermittent failure of didSelectRowAtIndexPath: being called on my custom cell press.
I discovered that if I stopped calling [tableView reloadData] very often (10 Hz), and changed it to update every 2 seconds, almost every press would successfully call didSelectRowAtIndexPath:
It seems like reloading the view blocks presses.
A cell can be selected by the user (tapping on the row), by calling "tableView.selectRowAtIndexPath(..)" or "cell.setSelected(true, ...).
If the cell is selected by calling "cell.setSelected(true)", the user cannot deselect the cell anymore.
If the cell is selected by calling "tableView.selectRowAtIndexPath()", the user can deselect the cell as expected.
Your problem is case-sensitivity. Your code:
- (void)tableVIew:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
should be
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {