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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:18:35+00:00 2026-06-15T06:18:35+00:00

I am quite stumped. I have an app with a class for storing item

  • 0

I am quite stumped. I have an app with a class for storing item details. Called LEItem. Those items are stored in a store with a class labeled LEItemStore. I have a view with a table of all items. This works fine. If you tap on a row, it sends this message to LogbookFirstViewController.

 LogbookFirstViewController *logController = [[LogbookFirstViewController alloc] initForNewItem:NO];

    NSArray *items = [[LEItemStore sharedStore] allItems];
    LEItem *selectedItem = [items objectAtIndex:[indexPath row]];

    NSString *description = [selectedItem description];
    NSLog(@"%@", description);

    [logController setItem:selectedItem];
    [self dismissViewControllerAnimated:YES completion:nil];

That is in a TableView class. In the LogbookFirstViewController.m I have

-(void)setItem:(LEItem *)i{
    item = i;
    NSString *t = [item description];
    NSLog(@"In LogbookFirstViewController, returning %@", t);
}

This is where it gets odd. That works. It outputs the correct item, therefore I would think everything would be okay. But it’s not. item is a class-level property, so it should stay, but it doesn’t. In the same class, I have overrode this method.

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    //NSString *string = [item description];
    //NSLog(@"Item = %@", string);
    NSLog(@"View did Appear:animated");
    int glucoseValue = [item glucose];

    NSString *glucoseString = [NSString stringWithFormat:@"%d", glucoseValue];
    [glucoseField setText:glucoseString];

    int proteinValue = [item protein];
    NSString *proteinString = [NSString stringWithFormat:@"%d", proteinValue];
    [proteinField setText:proteinString];

    int carbsValuue = [item carbs];
    NSString *carbsString = [NSString stringWithFormat:@"%d", carbsValuue];
    [carbsField setText:carbsString];

    int insulinValue1 = [item insulin];
    NSString *insulin1String = [NSString stringWithFormat:@"%d", insulinValue1];
    [insulinField1 setText:insulin1String];

    int insulinValue2 = [item insulin2];
    NSString *insulinString2 = [NSString stringWithFormat:@"%d", insulinValue2];
    [insulinField2 setText:insulinString2];



    //NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    //[dateFormatter setDateStyle:NSDateFormatterShortStyle];
    //[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    //NSLog(@" The item was created on %@", [dateFormatter stringFromDate:[item dateCreated]]);
    //[dateButton setTitle:[dateFormatter stringFromDate:[item dateCreated]] forState:UIControlStateNormal];
    NSString *t = [item description];
    NSLog(@"Loading view... Returns: %@", t);
}

I know that it isn’t the cleanest code, but the idea is the same. It uses exactly the same code as the setItem: method. However, this always returns (null). Why? The property appears to go missing at viewWillAppear.

Thanks.

EDIT

I solved the problem. As you can see, the checked answer below did give the right idea, here is what I did to solve it. The problem was that when I sent setItem: I used this code to get LogbookFirstViewController

 LogbookFirstViewController *logController = [[LogbookFirstViewController alloc] initForNewItem:NO];

As I know see, that created a new instance of LogbookFirstViewController, so therefore, the existing one did not change it’s Item property, as properties are assigned to one instance. Therefore, I was only changing the value of Item for this “invisible” property.

To solve this, one must get the existing instance of the viewController. To do this I did the following:

In LogbookFirstViewController.h I added this property

@property (assign) LogbookFirstViewController *instance;

Then, synthesize instance in your .m and in the same placed I added this to viewDidLoad

- (void)viewDidLoad
{
    instance = self;
    ...

Then, in the other viewController, entriesViewController, I added this too the .h

@property (nonatomic, strong) LogbookFirstViewController *logController;

Synthesize it. Then, I just used my didSelectRowAtIndexPath the same way, just using the existing logController

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


    NSArray *items = [[LEItemStore sharedStore] allItems];
    LEItem *selectedItem = [items objectAtIndex:[indexPath row]];

    NSString *description = [selectedItem description];
    NSLog(@"%@", description);
    NSLog(@"Setting controller: %@", logController);
    [logController setItem:selectedItem];
    [self dismissViewControllerAnimated:YES completion:nil];
}

Then it works!

  • 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-15T06:18:36+00:00Added an answer on June 15, 2026 at 6:18 am

    You have a line where you create the LogbookFirstViewController but you don’t actually cause it to display anything (push or present). Since it’s a local variable, it would appear that whatever instance of that controller is loading its view is not the same one that you initialize in the code you’ve shown.

    You can verify this by adding a couple of NSLog lines, such as:

    NSLog(@"Setting controller: %@", logController);  // Insert before existing line
    [logController setItem:selectedItem];
    

    …and…

    [super viewWillAppear:animated];
    NSLog(@"Viewing controller: %@", self);  // Insert after existing line
    

    For things to work the way you want, those have to print the same address.

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

Sidebar

Related Questions

i have been stumped on this for quite a while now. I am trying
I'm kind of stumped. I have a table of items with fields: ID, title,
I am truly stumped this afternoon and have done quite a bit of searching
I'm quite stumped on this issue. I have a large library of H.264 mp4
I have been stumped on this for quite awhile. Request#, SlotId, Segment, and Version
Quite some time i`ve learnt MVC. I have seen various techniques to post data
I have a PHP app built on Codeigniter 1.7.2, currently in production and live,
I am quite stumped with this. In enhancing an existing feature to a SharePoint
This has me stumped. This is quite a simplified version but let's say I
I have a table of people quite standard stuff e.g. : CREATE TABLE [Contact](

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.