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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:37:33+00:00 2026-06-08T05:37:33+00:00

I am attempting to use a UIViewController (View Controller) with a table view to

  • 0

I am attempting to use a UIViewController (View Controller) with a table view to send data to another UIViewController (Detail View Controller). My code looks like this:

//ViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"grapedetail"];
    detail.grape = [self.grapes objectAtIndex:indexPath.row];
    currentGrape = [self.grapes objectAtIndex:indexPath.row];
    NSLog(@"%@",currentGrape.searchName);
    [self.navigationController pushViewController:detail animated:YES];
    [self performSegueWithIdentifier:@"toGrapeDetail" sender:self];
}

//DetailViewController.m
- (void)viewDidLoad
{
    //obtain grape from table view
    //grape = ((ViewController *)self.presentingViewController).currentGrape; //I have also tried this method for obtaining the variable with the same result
    NSLog(@"Detail view says: %@",grape.searchName);
    //etc...
}

After I build the app I go to the View Controller and select a table cell to go to the Detail View Controller. Here is my output log:

2012-07-23 08:13:27.430 GrapeKeeper[593:f803] Detail view says: (null)
2012-07-23 08:13:27.432 GrapeKeeper[593:f803] Alarije

From this it seems that the detail view viewDidLoad is being called before the original VC’s didSelectRowAtIndexPath, even though I clearly want the latter to happen first so that the variable passes correctly. What can I do to fix this?

  • 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-06-08T05:37:35+00:00Added an answer on June 8, 2026 at 5:37 am

    Yes, this seemed extremely weird when I first encountered it, but also just the way it is.

    The trick is to do the work in prepareForSegue:sender: instead of didSelectRowAtIndexPath:. That way, you have the target controller as the segue’s destination.

    (Though, your code does look a bit confused concerning whether you’re pushing the controller or letting the segue do it.)

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

Sidebar

Related Questions

Attempting to use the data series from this example no longer passes the JSONLint
attempting to use this railscast as a guide: http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast and running into this error:
I am attempting to use this code sample to control the Windows XP On-Screen
I am attempting to use the data sources pluigin for rubymine 4.0.3 but I
I am attempting to use the following code to search a database using words
Attempting to use the amazon API to obtain product data and currently failing miserably.
I'm attempting to use MIB files in PySNMP. The code is fairly straightforward. Nothing
I am attempting to use Castle Windsor in my automated tests like so: On
I am attempting to use the MediaStore.ACTION_VIDEO_CAPTURE in my app, see code below. However,
I am attempting to use a button to go from one View (XIB) to

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.