NSTableView - Blank Row ??

Discussion in 'Mac Programming' started by Fritzables, Nov 24, 2011.

  1. Fritzables macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #1
    I am having trouble getting my head around the mighty NSTableView.

    Essentially, when reloading the data from the Array, I always end up with the first row containing blank rows.

    Below describes how I have stored data into a Dictionary during initialisation:
    Code:
    - (void)applicationDidFinishLaunching.... {
         record = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"",kCall, @"",kDate, @"",kTime, @"",kBand,nil];
        
        array = [NSMutableArray arrayWithObject:record];
    }
    This is obviously where the blank row originates from.

    I have a method that adds new data to the Dictionary by doing:
    Code:
    [array addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:call,kCall, date_,kDate, time_,kTime, band_,kBand,  nil]];
    So, when I reloadData to the table, I get the first row blank followed by showing the needed data in the rows below.

    What am I doing wrong?

    Pete
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    Why are you initialising array with a blank row?

    Can you not just do something like this?
    Code:
    array = [NSMutableArray array];
    

    BTW I'm worried about your memory management here. If array is a simple ivar, then I would have though you'd have been required to use alloc/init here instead of just array. If you were intending to use a retain property, then you'd have needed self.array, not just array.
     
  3. Fritzables thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #3
    G'Day Jim,

    Well... That's fair comment.

    In all od the tutorials I have seen to-date do the initialisation thing, which is mostly shown as empty Strings, then use the second listing I provided to add the data to.

    You have me thinking though Jim, I will play around following you suggestion to see how things turn out.

    Pete.
    (In a damm humid Brisbane)
     
  4. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #4
    One thing you could do, if writing your own dataSource (not using core data):

    • number of rows dataSource method: if the array's count is zero, return 1
    • value for key method: if row > the array's count, return a @""
    • set value method: if the row does not exist yet, create it

    You could modify this slightly so that the table will always display a blank row (that does not exist) at the bottom of the list, for the user's convenience.
     
  5. Fritzables thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #5
    G'Day Sydde,

    Thanks for the response - that is what I was trying to do originally but was unsure how one would implement it.

    Pete
     
  6. Fritzables thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #6
    Done it.....

    By placing:

    Code:
    array = [NSMutableArray arrayWithObject:record];
    [array removeAllObjects];
    It now does what I want to - not sure if this is the desired method, hey.... it works.

    Pete
     

Share This Page