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

  • SEARCH
  • Home
  • 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 7781907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:22:32+00:00 2026-06-01T19:22:32+00:00

When I click a certain list item in my UITableView, I want to pass

  • 0

When I click a certain list item in my UITableView, I want to pass the index of the item that I clicked on to the next detailed view.

This is my relevant code so far:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomeworkDetails *view =  [[HomeworkDetails alloc] init];


    int lastIndex = [indexPath indexAtPosition:[indexPath length] - 1];
    NSLog(@"%u", lastIndex);

    [self performSegueWithIdentifier: @"HomeworkDetailsSegue" sender:self];
    view.currentIndex = lastIndex;

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

At this point, I can successfully move on to the next ViewController (HomeworkDetails) but the information is not passed through. I am trying to accomplish this by doing view.currentIndex = lastIndex; but this is not working. How else can I do this? Sorry if I missed anything; I am a beginner at iOS development.

With suggestions:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    HomeworkDetails *view =  [[HomeworkDetails alloc] init];


    int lastIndex = [indexPath indexAtPosition:[indexPath length] - 1];
    NSLog(@"%u", lastIndex);

    [self performSegueWithIdentifier: @"HomeworkDetailsSegue" sender:self];
    view.currentIndex = lastIndex;

    [tableView deselectRowAtIndexPath:indexPath animated:YES];



}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"HomeworkDetailsSegue"]) {

        // note that "sender" will be the tableView cell that was selected
        UITableViewCell *cell = (UITableViewCell*)sender;
       NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; //**error**


        HomeworkDetails *vc = (HomeworkDetails*)[segue destinationViewController];
        vc.currentIndex = indexPath.row;
    }
}

Error from Compiler

  • 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-01T19:22:34+00:00Added an answer on June 1, 2026 at 7:22 pm

    What you are describing can best be done in the prepareForSegue:sender: method, instead of didSelectRowAtIndexPath:. In your storyboard, make sure your HomeworkDetailsSegue segue is set up between your tableView’s prototype cell and the destination view controller.

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {    
        if ([segue.identifier isEqualToString:@"HomeworkDetailsSegue"]) {
    
            // note that "sender" will be the tableView cell that was selected
            UITableViewCell *cell = (UITableViewCell*)sender;
            NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
            HomeworkDetails *vc = (HomeworkDetails*)[segue destinationViewController];
            vc.currentIndex = indexPath.row;
        }
    }
    

    Also, as a matter of style, I would recommend renaming your HomeworkDetails class to HomeworkDetailsViewController. Doing this follows Apple’s conventions more closely and makes it clearer what the class represents.

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

Sidebar

Related Questions

I have a contextmenu that shows on certain elements when you right click. This
I have a dropdown list that I want to show only certain options when
I'm writing a macro that will click certain spots on the screen when I
So this is my function, it deletes people from a list if you click
Hello I want to set the BorderColor of certain Item Renderers (textInput) of a
I have this code which applies a counter to each item on the list.
I have a JQuery Mobile (1.0rc1) application that has a list view with a
I'm trying to make it so that when you click on a certain element,
I have an iPhone app with a tableviewcontroller. When you click a certain cell
How do I check for a click on everything but a certain object? I

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.