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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:19:15+00:00 2026-06-03T21:19:15+00:00

I’m writing a small project time management program for myself and have run into

  • 0

I’m writing a small project time management program for myself and have run into a problem which has confounded me.

They way it’s set up is that I have an object called TCObject which I use in another object called ProjectTimerController. ProjectTimerController is a NSWindowController and it has it’s own NIB file.

What I’m doing is pretty straight forward. When you click a line in a NSTableView ProjectTimerController finds a TCObject which corresponds to that line. It then loads info from that TCObject into an interface where you can view and edit some stuff.
Here’s a screenshot of what it looks like:

Screenshot

Now when I change the text in NSTextView and then press the Add button the -saveString function is called and currentSelection (which is a TCObject and represents the currently selected line) and it’s notes variable is set. I know that _notes is set as the new value as NSLog function logs the correct string being in _notes when setString is run. The same, correct, string is logged in -tableViewSelectionDidChange: just before currentSelection is set as the newly selected object.

But if I select the line where I just changed the notes it just loads the same text, “Initial String” and checking _notes tells me it’s “Initial String”.

Thing I don’t have this problem with isFinished. When the Finished check box is toggled I set the corresponding TCObjects‘ isFinished Boolean value to the same value as the checkbox. This the object remembers and correctly changes depending on what line I have selected.

[EDIT]
*I’ve added a clearer explanation here.

  1. I click a line in the NSTableView (lets say the top one)

  2. This loads a corresponding TCObject from the myProjects array and that object’s variable are added to the Notes NSTextView box and Finished is toggled on or off.

  3. If I now write into The Notes box and press “Add” the text there is set into that TCObject’s _notes variable.

  4. So If I click another line some other text is loaded into the Notes box. Clicking back on the top line should give me the string I just wrote into Notes in step 3. But it doesn’t. _notes always seems to contain the string I set when I initialize it in the -init method.

  5. The “Finished” checkbox works fine. When I click that the state is saved and loaded correctly when I click a line.

  6. I know that _notes is correctly set when I press the Add button as the NSLog method in setString logs the string I have written into Notes when I press the Add button.

[/EDIT]

Here below is a barebones version of TCObject and ProjectTimerController.

//TCObject.h
@interface TCObject : NSObject
{
    NSString *_notes;
    Boolean _isFinished;
}

@property (retain, nonatomic) NSString *notes;
@property (nonatomic) Boolean isFinished;

@end
//TCObject.m
#import "TCObject.h"

@implementation TCObject
@synthesize notes = _notes, isFinished = _isFinished;

-(id)init{
    if (self = [super init]) {
        self.notes = @"Initial string";
        self.isFinished = NO;
    }
    return self;
}

- (void)dealloc {   
    [_notes release]; _notes = nil;
    [super dealloc];
}


-(void)setNotes:(NSString *)notes {
    [notes retain];
    [_notes release];
    _notes = notes;
    NSLog(@"Setting _notes as: %@", _notes);

}


-(NSString *)notes {

    NSLog(@"Getting _notes, which is: %@", _notes);
    return _notes;
}

@end
//ProjectTimerController.m
- (id)initWithWindow:(NSWindow *)window {
    self = [super initWithWindow:window];
    if (self)
    {
        myProjects = [[NSMutableArray alloc]init];
        currentSelection = nil;

        TCObject *newProject = [[TCObject alloc] init];
        TCObject *newProject2 = [[TCObject alloc] init];
        TCObject *newProject3 = [[TCObject alloc] init];
        TCObject *newProject4 = [[TCObject alloc] init];

        [myProjects addObject:newProject];
        [myProjects addObject:newProject2];
        [myProjects addObject:newProject3];
        [myProjects addObject:newProject4];
    }
    return self;
}


-(IBAction)isFinishedToggle:(id)sender {
    if(currentSelection != nil){
        currentSelection.isFinished = finishedCheckBtn.state;
    }
}


-(IBAction)saveString:(id)sender {
    if(currentSelection != nil){
        currentSelection.notes = [[notesField textStorage] string];
    }
}

//delegate function for NSTableView
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
    NSInteger selectedIndex = [table selectedRow];

    if(selectedIndex == -1){
        return;
    }
    //here the correct notes string is printed
    NSLog(@"curr: %i", currentSelection.notes);

    currentSelection = [myProjects objectAtIndex:selectedIndex];

    NSString *notesInfo = currentSelection.notes;
    Boolean isFinishedInfo = currentSelection.isFinished;

    [notesField setString:notesInfo];
    [finishedCheckBtn setState:isFinishedInfo];
}
  • 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-03T21:19:18+00:00Added an answer on June 3, 2026 at 9:19 pm

    Finally found the problem. Seems that changing notes in this way:

    -(IBAction)saveString:(id)sender {
        if(currentSelection != nil){
            currentSelection.notes = [[notesField textStorage] string];
        }
    }
    

    causes some problems. Everything works fine if I do it this way:

    -(IBAction)saveString:(id)sender{
        if(currentSelection != nil){
            NSString *temps = [NSString stringWithFormat:@"%@", [[notesField textStorage] string]];
            currentSelection.notes = temps;
        }
    }
    

    So I’m guessing what was going on is that _notes was pointing to the text contained in my NSTextView. So when I changed the text there _notes also changed or something like that…

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.