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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:09:03+00:00 2026-06-17T06:09:03+00:00

I have a tableView where I can select a ship from a list, and

  • 0

I have a tableView where I can select a ship from a list, and when I tap it I want the information to pop up on another screen. The way I am currently doing this is:

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

cargoShips* ship=[boatsForOwner objectAtIndex:indexPath.row];
UITableViewCell *cell = [self.boatsTableView cellForRowAtIndexPath:indexPath];

[self performSegueWithIdentifier:@"boatInfoSegue" sender:cell];




NSString *nameString = ship.name;
NSString *sizeString = ship.size;


NSUserDefaults *shipName = [NSUserDefaults standardUserDefaults];
[shipName setObject:nameString forKey:@"globalName"];
[shipName synchronize];
NSUserDefaults *shipSize = [NSUserDefaults standardUserDefaults];
[shipSize setObject:sizeString forKey:@"globalSize"];
[shipSize synchronize];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

And to load it back into text (in another file)

 NSString *getName = [[NSUserDefaults standardUserDefaults]
                     objectForKey:@"globalName"];
NSString *getSize = [[NSUserDefaults standardUserDefaults]
                     objectForKey:@"globalSize"];

shipNameText.text = getName;
shipSizeText.text = getSize;

Now , this works great, except for the fact that it does not return the cell I selected to get to the infoView, but the previous selected object. So if I select the first object on the list, it returns null, the next item i select gets the result I should have had for the first object and so on.

What did I do wrong and how can I fix it?

  • 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-17T06:09:04+00:00Added an answer on June 17, 2026 at 6:09 am

    NSUserDefaults is tool for saving settings, not for transferring object.
    If I were you I made it this way:

    #pragma mark - Segue
    - (void)prepareForSegue:(UIStoryboardSegue *)segue
                     sender:(id)sender {
        if ([segue.identifier isEqualToString:@"boatInfoSegue"]) {
    
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            CargoShip *ship = boatsForOwner[indexPath.row];
    
            BoatViewController *vc = (BoatViewController *)segue.destinationViewController;
            vc.ship = ship;      
        }
    }
    

    Class names should be capitalized, that’s why I wrote CargoShip

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

Sidebar

Related Questions

I have created a TableView(Grouped Table View). And I can list the items in
Currently i have a uitableview that the user can scroll through and select a
I have 5 cells in my tableview. User can select a row which sets
I have a tableView that present a list of Books, each of the table
I have a TableView with 10 sections that are loaded from a plist file
i have a tableView with 3 cells. i want to change .detailTextLabel of that
i have made one list of images + respective data in tableview. it takes
I have a UITableViewController that shows a list of items from NSMutableArray, along with
I have tableview with some names on each cell , how can i get
I have designed a Table view , For Select Followers list to send message,

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.