Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7410847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:17:44+00:00 2026-05-29T06:17:44+00:00

I have a UITableViewController with a segue where I’m trying to get the currently

  • 0

I have a UITableViewController with a segue where I’m trying to get the currently selected row:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([[segue identifier] isEqualToString:@"EditFilterElementSegue"]){
        // Get the element that was clicked and pass it to the view controller for display
        NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
        Element *element = [fetchedResultsController objectAtIndexPath:selectedIndexPath];
        FilterElementTableViewController *vc = segue.destinationViewController;
        vc.filter = filter;
        vc.element = element;
    }
}

The problem is indexPathForSelectedRow is returning nil. The docs say nil is returned “if the index path is invalid”. If I add:

        [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:0];
        selectedIndexPath = [self.tableView indexPathForSelectedRow];

selectedIndexPath is valid. So, I’m currently assuming the row is somehow getting unselected. Can anyone tell me how to figure out if this is the case and what might be causing it?

This code worked fine until I converted to using NSFetchedResultsController (which otherwise is working). I also use indexPathForSelectedRow in several other table view controllers where it works fine (one of which also uses NSFetchedResultsController).

I’ve also tried breaking in didSelectRowAtIndexPath, but the same thing happens there. (expected since it’s called after prepareForSegue.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:17:45+00:00Added an answer on May 29, 2026 at 6:17 am

    Ok, the bottom line is the scene in storyboard was messed up.

    To figure it out I removed the segue and created a brand new empty UITableViewController class and only added enough code so I could click on a row and look at indexPathForSelectedRow. It was still nil.

    I then created a new UITableViewController in storyboard and replaced the existing one. Now indexPathForSelectedRow worked.

    I copied all the class code over, and the prototype cells over, and it still worked!

    Out of curiosity I looked at the storyboard source for the two scenes and noticed that the scene that wasn’t working was much longer than the new one. Looking at the storyboard outline it was obvious why, and surprising it worked at all. And, now I remember having trouble cutting & pasting a prototype cell. Guess I should look at the outline mode more often. See the screen shot below (the visual scenes look the same):

    Storyboard screen shot

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableViewController and DetailViewController that pops up when concrete row is selected.
I have a segue linked from a UITableViewCell to another UITableViewController within a navigation
I have a UITableViewController (called Details). In that tableView on row 1 I have
I have a UITableViewController containing some very basic data. Assume each row just contains
I have a UITableViewController, a bunch of sections and rows, and for each row
I have UITableViewController (initiated by the Navigation-based app project template). I am overriding loadView
I have a UITableViewController. In viewDidLoad I set the rowHeight: self.tableView.rowHeight = 43; But
I have an UITableViewController which I would like to add UIToolbar to with one
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a UIPickerView as subview in a UITableViewController, which I want to slide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.