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
5
votes
3 answers

Use an unwind segue in didSelectRowAtIndexPath?

I have a root view controller A which push segues to a table view controller B. And when a row is selected in B. I want to use an unwind segue to go back to A and pass the text in the row back to the root view A. And then I use the the prepare for…
user3662854
5
votes
6 answers

UITableView last row didSelect not working properly?

I'm facing a very strange problem. I'm using a tableView for menu purpose. It is working fine. But the problem is that in last row of that table ,only top half area fires did select event. When I click on mid of the last row did select does not…
Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90
5
votes
2 answers

Storyboard segue gets called before UITableView's didSelectRow

I have a storyboard with segue from a table cell. I want to set some properties with some data when a row gets selected so I do the following: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { …
Mohamed Emad Hegab
  • 2,665
  • 6
  • 39
  • 64
5
votes
2 answers

what is the difference between didselectrowindexpath and willselectrowindexpath in iphone?

Give an explanation about difference between UITableView delegate methods: didDeselectRowAtIndexPath: -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath and willSelectRowAtIndexPath -(NSIndexPath…
user1208852
4
votes
7 answers

didSelectRowAtIndexPath with section

I have a UITableView which I have assigned sections. When using didSelectRowAtIndex with indexPath.row I am not getting the correct value. Let's say I'm in section 2, then it starts the row index at 0 again and therefore I am getting the wrong…
simonbs
  • 7,932
  • 13
  • 69
  • 115
4
votes
1 answer

"didSelectRowAtIndexPath" method never called on iOS 10 devices

My current app is available on the store for several months now. This app contains several UIListView, using custom cells (each cell in its own NIB) and touching a cell was always functional. Now, without any update of the app, it appears since iOS…
4
votes
1 answer

UICollectionView allow multiple selection for specific section

Is there a way to allow multiple selection only for a specific section? The code below affects all sections. [self.collectionView setAllowsMultipleSelection:YES]; Should i keep track of the states and do something in didSelect?
4
votes
1 answer

didSelectItemAtIndexPath not called with multiple collection views on same screen

I have 2 collection views on the same screen, and I have the data source and delegate implemented for both in the same view controller. However, the delegate methods such as didSelectItemAtIndexPath is only called for one. Other info: Both…
iagomr
  • 442
  • 4
  • 13
4
votes
2 answers

popoverPresentationController's sourceView inside didSelectRowAtIndexPath in iPad in Swift

I want to show an popoverPresentationController when user click an cell in iPad. Here's my code: override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if(indexPath.section == 0){ …
4
votes
1 answer

Expandable Sections UITableView IndexPath SWIFT

Im pretty new to coding, I only know Swift. I have found several tutorials to produce drop down sections in a table. Basically it will represent a TV show, the headers will be the seasons and the drop down list of episodes from each season. I…
4
votes
1 answer

Trying to update label with didSelectRowAtIndexPath

I have a tableView populated with information from a JSON array. When I click on that cell, it segues into a DetailsViewController where it should display a label that displays the text of the cell that was clicked on (in my case it is title, or…
videoperson
  • 139
  • 1
  • 12
4
votes
6 answers

Unable to pushViewController for subview

I have a UINavigationController and I have seperate UIViews that I switch between using a UISegmentControl. On switching the views, I add the view as a subview to my navigation controller's view: [self.view…
runmad
  • 14,846
  • 9
  • 99
  • 140
4
votes
1 answer

Passing Data Between View Controllers DidSelectRowsAtIndexPath Storyboards

In a simple test app, i have tried to pass an array object named "thisArray" from the MasterViewController to the a string named "passedData" in the DetailViewController. I am using Storyboards and the UIViewController are embedded inside the…
AJ112
  • 5,291
  • 7
  • 45
  • 60
3
votes
3 answers

Strange Behavior-Did select row touch not responding for UITableViewCell

I have a very strange problem,I don't know whether it is awkward to normal behavior of cells or not,it seems as if it is so!Hence I am giving it up to some one who can answer, apologize if any thing stupid in asking this question.Normally,when we…
Eshwar Chaitanya
  • 697
  • 10
  • 21
3
votes
1 answer

viewDidLoad being called before didSelectRowAtIndexPath

I have viewDidLoad (of next tableView) being called before didSelectRowAtIndexPath (of current tableView). I am using a 'singleton' to hold my model and up to now this has been working quite well. I am trying to pass on the row selected in the…
1 2
3
41 42