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 7644853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:47:22+00:00 2026-05-31T09:47:22+00:00

I have a UITableView showing data from a plist file. For this table view,

  • 0

I have a UITableView showing data from a plist file. For this table view, I’ve simply made an NSArray from the contents of the plist file and fed the data into each cell. But when a cell is tapped, I need the next table view controller to know the index path of the cell that was tapped so that this view controller knows which item in the array to show details for. I’ve tried the following method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    staffDetailView = [[StaffDetailViewController alloc] init];
    [staffDetailView setSelectedIndexPath:indexPath];

    [self performSegueWithIdentifier:@"pushStaffDetailView" sender:self];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Above, I’m attempting to pass the index path of the tapped cell to an NSIndexPath object that I’ve created in the new view controller.

The next table view controller’s header file:

@interface StaffDetailViewController : UITableViewController {

    NSIndexPath *selectedIndexPath;
    NSArray *staffArray;

}

@property (nonatomic, retain) NSIndexPath *selectedIndexPath;
@property (nonatomic, strong) NSArray *staffArray;

Here I define the selectedIndexPath object that was set in the previous view controller.

But when I try to access the selectedIndexPath object to display the relevant data, the object appears to be nil:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *header;
    if (section == 0) {
        NSString *name = [[staffArray objectAtIndex:selectedIndexPath.row] objectForKey:@"Staff Member"];
        NSArray *splitStaffArray = [name componentsSeparatedByString:@", "];
        NSString *lastName = [splitStaffArray objectAtIndex:0];
        NSString *firstName = [splitStaffArray objectAtIndex:1];
        NSString *consolidatedName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
        NSString *assignment = [[staffArray objectAtIndex:selectedIndexPath.row] objectForKey:@"Assignment"];
        header = [NSString stringWithFormat:@"%@\n%@", consolidatedName, assignment];
        return header;
    }
    return nil;
}

Am I accessing the selectedIndexPath object incorrectly? Is there a superior method for passing the correct index path to the next view controller?

  • 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-31T09:47:23+00:00Added an answer on May 31, 2026 at 9:47 am

    I revised the first table view controller’s didSelectRowAtIndexPath method:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        [self performSegueWithIdentifier:@"pushStaffDetailView" sender:self];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        [staffDetailView setSelectedIndexPath:indexPath];
        [staffDetailView setPassedName:[[staffArray objectAtIndex:indexPath.row] objectForKey:@"Staff Member"]];   
    
    }
    

    It seemed that for some reason I needed to perform the segue before accessing that view controller’s instance variables. Strange that I couldn’t just alloc init the view controller its self. Anyhow, the index path is now being correctly pushed across view controllers.

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

Sidebar

Related Questions

I have the following code showing location objects from an NSArray in a table,
I have the right view selected from my PopOver but instead of showing in
I have a data-structure (in plist) that looks something like this: What i have
I have a TabBarApplication and in one view I load XML-data from an URL.
I have a table view that's showing a list of bank transactions. When I
I have an UITableView showing custom view cells that I've designed in interface builder.
I have seen many apps that load data to UITableViews from the internet, and
I am working in a app where i have data in UITableView . It
I'm trying to make my Core data backed UITableView have reorder ability, After implement
Do you know how to have some cells appear in a table view after

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.