Update a NSArrayController through NSTextField automatically

Discussion in 'Mac Programming' started by Beb, Oct 28, 2009.

  1. Beb macrumors newbie

    Oct 28, 2009
    Paris, France.
    Hello everyone,

    Well, as it is my first post, let me introduce myself !

    My name is Bertrand, I currently live in France (Paris, to be precise), so that'll be the reason of some flaws in my english... But i'm doing the best I can :)

    I'm a Mac user since one year and particulary fond of it ! I can't beleive I was on PC before. I started Cocoa programming 1 month ago, so I'm quite a newbie, but kinda likes how to work with it :)

    Anyway, I was lurking here since one good week and your help already paid off !

    So, let's explain my problem :

    The context :
    I'm currently working on an App that'll sync two folders, in order to have every some documents folders synced between my iMac and MacBook. None of the solutions found on the internet fit me, or they were not free ! I thought that will be a nice project to start my discovery of Cocoa.

    Once this application was made, I thought : "Hey, why not having Favorites, so I'll not have to select everytime the Source folder and the Target folder ?!".

    So, I started to look after Core Data. I created an entity, attached a NSArrayController to it, and built an interface to play with this. Here is a quick summary of the interface :
    - "Favorite" name selection, through a NSPopUp
    - Favorite's name : an NSTextField, updated when selecting the Favorite in the NSPopUp
    - Favorite's Source folder : an NSTextField, updated when selecting the Favorite in the NSPopUp
    - Favorite's Target folder : an NSTextField, updated when selecting the Favorite in the NSPopUp
    Those NSTextFields are correctly bound to their related Keys in the NSArrayController...

    I have a button to Add a new favorite (binded to the "add:" method of the controller) and a button Remove a favorite (binded to the "remove:" method of the controller)

    Now, eveything works fine : Selecting an item in the NSPopUp refreshes the NSTextFields, Adding works perfectly, Editing is fine, and Deleting does what it's supposed to.

    The issue now :
    To prevent user errors, I added a button "Get Pathes", that will fill the two NSTextFields (Source and Target) with the data already entered in the "main" window of the application.

    This is done with those basic lines of code :
    [textFavSource setStringValue:[textMainSource stringValue];
    [textFavTarget setStringValue:[textMainTarget stringValue];

    And this works like a charm...

    But, the only problem is that the values are not stored in the data, just like when typing text directly in the NSTextFields ! Values are changed when clicking the button, but when I select another Favorite from the NSPopUp, then chose back the one I wanted modified, the values are left to the ones it had before clicking the button.

    It looks like just putting the text in the NSTextFields does not actually updates the data... I think I should find a way to force the data to be saved, but didn't find a way how to...

    I made a lot a search to no avail :'(

    Help would be greatly appreciated :)

    See you around !


Share This Page