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
0
votes
1 answer

backgroundTap hides didSelectRowAtIndexPath

I have a UITableView with some UITableViewCells that contain labels with suggestions for text to be inserted into a UITextView. I want that when the user taps on some uitableviewcell with text suggestion, this text will enter the uitextview, but I…
Tomer
  • 189
  • 1
  • 3
  • 11
0
votes
2 answers

UITableViewCell textLabel height resets after selecting/highlighting same cell

I have an issue regarding UITableViewCell's textLabel property when reselecting (touching without lifting a finger) a cell that's already selected. I have a custom contentView being added in the background just below the textLabel that has a dynamic…
0
votes
3 answers

Selecting Cell in Table IOS

I am trying to create a method that changes the string object "tableColorName" to the cell selected. The tableData NSArray consists of object: "red","blue","green". I want to save the string "tableColorName" to redColor if red is selected, blueColor…
0
votes
1 answer

didSelectRowAtIndexPath is not being called in included nib

I've a class say clsBase, is the base class of all other classes. And I've a Title class which contains TitleBar at the top. In TitleBar nib there's a menu button clicking on it, it shows a UITableView. This UITableView is in the TitleBar nib…
Mohit Mehta
  • 1,283
  • 12
  • 21
0
votes
1 answer

Tapping UIButton in custom cell doesn't call didSelectRowAtIndexPath

I have a UIButton in a custom cell that I programmatically added: UIButton *tag = [[UIButton alloc] init]; [tag addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; And this is my button…
Endokun
  • 13
  • 2
0
votes
1 answer

UITableView behin UIScrollView

For my needs I have a UITableView directly added under a UISCrollView : --- Main UIView -------- UITableView -------- UIScrollView So when I scroll my scrollview I change the content offset of my tableview. It works perfectly. But when I tried to…
0
votes
1 answer

Using identity of pressed button & array row to perform segue

I'm just starting with iOS and objective C and one of the things that I'm trying to accomplish in my current app is to perform a segue based on the identity of the row in the table view and identity of the button pressed (these are buttons on top in…
0
votes
3 answers

iOS: Check values? NSDictionary, NSArray, NSString

Skip the following These values are the first three lines of a TVC didSelectRowAtIndexPath method which is giving me all kinds of exceptions when I select an item in a row. How do I: a. Check that the below dictionary, array and selectedCategory…
Morkrom
  • 578
  • 7
  • 26
0
votes
2 answers

didSelectRowAtIndexPath: only being invoked after ~3 second hold on cell

I am loading my cells from a nib, which are subclasses of UITableViewCell. Each of these cells are setup with userInteraction set to YES (in the nib file). When tapping on a cell, the selection of the cell isn't shown (in this case grey) unless the…
Adam Carter
  • 4,741
  • 5
  • 42
  • 103
0
votes
2 answers

TableView didSelectRowAtIndexPath before ViewDidLoad

I want didSelectRowAtIndexPath to execute before ViewDidLoad. How to do it? in didSelectRowAtIndexPath : [[NSUserDefaults standardUserDefaults] setObject:[[array objectAtIndex:indexPath.row + 1] objectForKey:@"gid"]…
egor.zhdan
  • 4,555
  • 6
  • 39
  • 53
0
votes
1 answer

UITableview - didSelectRowAtIndexPath shows different data issue

I am parsing RSS to UITableview and the data looks as it should but when I select one of the field in the UITableview it opens different data then what it should. Also when I scroll the tableview the same field that I have selected gives again…
Luai Kalkatawi
  • 1,492
  • 5
  • 25
  • 51
0
votes
1 answer

UITableViewCell selection stays in all cells !

I am still in the process of getting myself acquainted with the iPhone SDK. This is what I am trying to do : I have a UIScrollView and each scroll view has an UITableView and I have implemented a custom UITableViewCell. The desired functionality is…
Amy Fudge
0
votes
1 answer

Passing a core data object to a sub view on didSelectRowAtIndexPath

I have a core data setup that has 2 database entities. For the sake of names I'll call them Primary and Secondary. Secondary only belong to one Primary (relationship is setup). In my main view that lists the Primary objects in a table I retrieved…
Designer023
  • 1,902
  • 1
  • 26
  • 43
0
votes
2 answers

How to save an item from didSelectRowAtIndexPath: to NSUserDefaults

I'm trying to save the cell title of a selected table view row to NSUserDefaults. I have the following code in the didSelectRowAtIndexPath: method. At the moment this saves the entire listOfItems (an NSMutableArray). I would like to be able to save…
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
0
votes
1 answer

xcode pass object using segue

I am trying to pass an object from a view controller to another one. In the destinationController I have: @interface destinationController : UITableViewController{ destinationController *object; @property(nonatomic,copy) destinationController…
J-K
  • 139
  • 11