TableColumn visibility issue

  • Folks;
    [Sorry for the earlier 'no subject' posting!!]

    I am trying to allow the user to manage which table columns are visible.
    I have everything working very nicely within a given application launch.

    I was under the impression that the tableView in the nib is archived
    and not altered by any of the addTableColumn/removeTableColumn activity.
    However, during a later application launch, when I read the [tv
    tableColumns] in the tableView's -awakeFromNib what I find  is that
    only the columns which were visible when the application was last
    terminated are there.

    So when the user attempts to add back a column in this later run of
    the application it fails because I no longer have anything which
    points to the invisible columns....???

    This is a non-document based app.
    The table columns have bindings for value, fontName, fontSize, and
    textColor.

    Subclassed TableView
    - (void) awakeFromNib {
    NSArray * t = [self tableColumns];
    NSMutableDictionary*workDict = [NSMutableDictionary
    dictionaryWithCapacity:[t count]];
    NSEnumerator * thisEnum = [t objectEnumerator];
    NSTableColumn *tc;
    while ((tc=[thisEnum nextObject])!=nil) {
      [workDict setObject:tc forKey:(NSString *)[tc identifier]];
    }
    [self setMyTableColumns:workDict];  //this is an KVC compliant
    dictionary instance var
    }

    WindowController
    - (void) windowDidLoad {
    ...
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    if ([ud boolForKey:@"hideFistName"] == YES) [listTableView
    removeTableColumn:[[listTableView myTableColumns]
    objectForKey:@"firstName"]];
    if ([ud boolForKey:@"hideLastName"]  == YES) [listTableView
    removeTableColumn:[[listTableView myTableColumns]
    objectForKey:@"lastName"]];
    ...etc..
    }

    - (IBAction) toggleColumnVisibility:(id)sender {
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSTableColumn *TC;
    switch ([sender tag]) {
      case 0:
      TC = [[listTableView myTableColumns] objectForKey:@"firstName"];
      if ([ud boolForKey:@"listDockHideFirstName"] == YES)
    [listTableView removeTableColumn:TC];
      else [listTableView addTableColumn:TC];
      break;
      case 1:
      TC = [[listTableView myTableColumns] objectForKey:@"lastName"];
      if ([ud boolForKey:@"listDockHideLastName"] == YES) [listTableView
    removeTableColumn:TC];
      else [listTableView addTableColumn:TC];
      break;
    ...etc..
    }

    What am I doing wrong?
    It all works great within one launch!

    Thanks for any thoughts!
    Steve
  • Do you save the positions of columns with the Auto-save name?

    On dimanche, octobre 14, 2007, at 09:43  PM, Steve Cronin wrote:

    > I am trying to allow the user to manage which table columns are
    > visible.
    > I have everything working very nicely within a given application
    > launch.
    >
    > I was under the impression that the tableView in the nib is archived
    > and not altered by any of the addTableColumn/removeTableColumn
    > activity.
    > However, during a later application launch, when I read the [tv
    > tableColumns] in the tableView's -awakeFromNib what I find  is that
    > only the columns which were visible when the application was last
    > terminated are there.
    >
    > So when the user attempts to add back a column in this later run of
    > the application it fails because I no longer have anything which
    > points to the invisible columns....???
    >
    > This is a non-document based app.
    > The table columns have bindings for value, fontName, fontSize, and
    > textColor.
    > [...]
  • On 2007 Oct, 14, at 12:43, Steve Cronin wrote:

    > I was under the impression that the tableView in the nib is archived
    > and not altered by any of the addTableColumn/removeTableColumn
    > activity.

    Yes, that is correct.  (Or else we're all in big trouble!)

    > However, during a later application launch, when I read the [tv
    > tableColumns] in the tableView's -awakeFromNib what I find  is that
    > only the columns which were visible when the application was last
    > terminated are there.

    It looks to me as though these statements in -windowDidLoad will do
    that...

    > NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    > if ([ud boolForKey:@"hideFistName"] == YES) [listTableView
    > removeTableColumn:[[listTableView myTableColumns]
    > objectForKey:@"firstName"]];
    > if ([ud boolForKey:@"hideLastName"]  == YES) [listTableView
    > removeTableColumn:[[listTableView myTableColumns]
    > objectForKey:@"lastName"]];

    Your NSUserDefaults, ud, ^are^ saved between application launches, in
    ~/Library/Preferences/com.myCompany.MyApp.plist
  • Stephane;

    THANK-YOU!!

    I simply added:
    ...
    [listTableView setAutosaveTableColumns:YES];
    ...

    to the windowController -awakeFromNib and it now works great!!

    Thanks!!
    Steve

    On Oct 14, 2007, at 3:26 PM, St├ęphane Sudre wrote:

    > Do you save the positions of columns with the Auto-save name?
    >
    > On dimanche, octobre 14, 2007, at 09:43  PM, Steve Cronin wrote:
    >
    >> I am trying to allow the user to manage which table columns are
    >> visible.
    >> I have everything working very nicely within a given application
    >> launch.
    >>
    >> I was under the impression that the tableView in the nib is archived
    >> and not altered by any of the addTableColumn/removeTableColumn
    >> activity.
    >> However, during a later application launch, when I read the [tv
    >> tableColumns] in the tableView's -awakeFromNib what I find  is that
    >> only the columns which were visible when the application was last
    >> terminated are there.
    >>
    >> So when the user attempts to add back a column in this later run of
    >> the application it fails because I no longer have anything which
    >> points to the invisible columns....???
    >>
    >> This is a non-document based app.
    >> The table columns have bindings for value, fontName, fontSize, and
    >> textColor.
    >> [...]
    >
    >
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today