Questions tagged [didselectrowatindexpath]

iOS - didSelectRowAtIndexPath: is a UITableView delegate method which is called when the user selects a row on a table view. Navigation logic goes here.

– tableView:didDeselectRowAtIndexPath:

iOS Method within UITableView (Apple Docs)

Full method decleration:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

Overview

didSelectRowAtIIndexPath: is a method part of the delegate. The UITableView delegate handle setup and events for a UITableView.

This method is called when a user selects a row in the table view, and takes an argument of NSIndexPath. The NSIndexPath contains the row, and section of the cell which was selected. Within this method, actions are performed to react to a user's selection.

Unlike this method, willSelectRowAtIndexPath: is used to allow or disallow a selection based on the index path.

Similar methods include:

– tableView:willSelectRowAtIndexPath:
– tableView:willDeselectRowAtIndexPath:
- tableView:didDeselectRowAtIndexPath:

Sample Code

An implementation of this method designed to handle navigation logic might look like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) {
    NSUInteger row = [indexPath row]; // Easier to cache row, esp. in long methods

    // In viewDidLoad you would have set up an array of controllers, then:
    UIViewController *childController = [controllerArray objectAtIndex:row];
    [self.navigationController pushViewController:childController];
}
629 questions
357
votes
16 answers

UITableView didSelectRowAtIndexPath: not being called on first tap

I'm having an issue with UITableView's didSelectRowAtIndexPath. My table is setup so that when I select row it initializes a new view controller and pushes it. The first time I tap any row in the table, the method does not get called. Once I select…
Mark Adams
  • 30,776
  • 11
  • 77
  • 77
307
votes
60 answers

-didSelectRowAtIndexPath: not being called

I'm writing an iOS app with a table view inside a tab view. In my UITableViewController, I implemented -tableView:didSelectRowAtIndexPath:, but when I select a row at runtime, the method isn't being called. The table view is being populated though,…
Matt Pfefferle
  • 209
  • 2
  • 6
  • 14
71
votes
2 answers

didSelectRowAtIndexPath returns wrong IndexPath

I have encountered a really puzzling bug. The first row of my UITableView returns 1 and the second one returns 0 in the indexPath! How is that even possible? In my `-(void)viewDidLoad` everything is still fine. I am highlighting the first row…
Mundi
  • 79,884
  • 17
  • 117
  • 140
60
votes
14 answers

didSelectRowAtIndexPath: not being called

I have a UITableView as a subview of my UIScrollVIew, which is the main view controlled by my MainViewController. In MainViewController.h @interface MainViewController : UIViewController
Garrett
  • 5,580
  • 2
  • 31
  • 47
31
votes
2 answers

prepareForSegue called before didSelectRowAtIndexPath only when third segue is added

I have 3 segues to 3 different views. 2 are implemented with no problem, it is when the third is created that the problems occur. I have the following didSelectRowAtIndexPath method: - (void)tableView:(UITableView *)tableView…
Atma
  • 29,141
  • 56
  • 198
  • 299
27
votes
7 answers

UITableView didSelectRowAtIndexPath not being called on first tap

I'm having an issue with UITableView's didSelectRowAtIndexPath of ios 5, which is correct in ios 4. The first time I tap any row in the table, the method does not get called. Once I select another row, it call the didSelectRowAtIndexPath, but pass…
meggy.meng
  • 271
  • 1
  • 4
  • 5
18
votes
5 answers

UITableView didSelectRowAtIndexPath called twice

Under certain circumstances, UITableView didSelectRowAtIndexPath is being called twice causing the error Pushing the same view controller instance more than once is not supported. Here's are the sequence of…
ED.
  • 231
  • 2
  • 4
16
votes
7 answers

Get row number of UITableview with multiple sections

I have a UITableView, with multiple sections in it, and each section has multiple rows. I want to get the row number of selected cell with respect to the entire table and not the section only. example: I have two sections in the UITableView,…
Hyder
  • 1,163
  • 2
  • 13
  • 37
15
votes
2 answers

Multiple checkMark when row selected in UITableView IOS

I have a UITableView that displays checkmarks when a row is selected. The problem is that When i select a row in didSelectRowAtIndexPath and add a checkmark on the selected row it adds an additional checkmark. Here's my code Any help would be very…
Klinkert0728
  • 326
  • 1
  • 4
  • 14
14
votes
1 answer

Segue from UITableViewCell how to include indexPath data?

I have a segue linked from a UITableViewCell to another UITableViewController within a navigation controller, and I need to setup the second UITableViewController based on the cell I'm segueing from. The didSelectRowAtIndexPath method gives me that…
sickagain
  • 143
  • 1
  • 4
14
votes
4 answers

To Segue or to didSelectRowAtIndexPath?

Below is the code that I am currently running. I have a storyboard setup with a nav controller and tableview controller and a view controller. I am trying to pass the name from the NSDictionary that I have setup for the Table to the detail view…
13
votes
4 answers

Select ALL TableView Rows Programmatically Using selectRowAtIndexPath

I'm trying to programmatically select all rows in my tableview using the following code: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell:myTableViewCell =…
Tom
  • 790
  • 2
  • 9
  • 32
12
votes
3 answers

didSelectRowAtIndexPath is not getting called

I am adding UIScrollView in UITableViewCell, but when I am click on scroll view did select method is not getting called. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath I am adding the scroll view on…
vntstudy
  • 2,038
  • 20
  • 24
11
votes
2 answers

Swift: UICollectionView selecting cell indexPath issues

I am trying to do a Collection View whereby someone selects a cell and for each selection it takes them to another View Controller that holds content of the selection. However I'm running into difficulties as once I apply this line of code to…
10
votes
6 answers

Swift. Change Color of Custom Tableview Cell Label when selected

I have a Custom Tableview cell in swift and in that cell a label. I want to be able to change the label when you select a cell. How can I reference my custom UITableviewCell label in didSelectRowAtIndexPath In Objective C to reference my custom cell…
1
2 3
41 42