Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fritzables

macrumors regular
Original poster
May 6, 2011
149
1
Brisbane AUSTRALIA
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
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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.
 

Fritzables

macrumors regular
Original poster
May 6, 2011
149
1
Brisbane AUSTRALIA
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)
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
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.
 

Fritzables

macrumors regular
Original poster
May 6, 2011
149
1
Brisbane AUSTRALIA
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.