0
votes

I have a NSTableView which works fine except that it only shows a screen's worth of data. I've checked as it loads and all data is in the source Arrays (3 columns = 3 Mutable Arrays). All rows seem to be there but, when I scroll up (or down, depending on your viewpoint), the rows that were off-screen are blank.

I increased the height of the Table View and more data appeared but with the same effect for off-screen rows. In fact, I built the table by copying from an earlier version which works fine - and I've done a comparison of properties and can't see any differences.

Any ideas. I'm happy to add code but I'm not even sure what to show you.

To confirm build, the tableView code:

- (NSString *) returnedValue: (NSString *) keyName forRow: (NSUInteger) row
{
    if( [keyName isEqualToString: Col1Id] )
    {
        return [actuelColDesc objectAtIndex: row];
    }
    else if( [keyName isEqualToString: Col2Id] )
    {
        return [actuelColSing objectAtIndex: row];
    }
    else if( [keyName isEqualToString: Col3Id] )
    {
        return [actuelColPlur objectAtIndex: row];
    }
    return nil;
}

#pragma mark - Table View Data Source

- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
    return self.actuelColDesc.count;
}

- (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    return [self returnedValue: tableColumn.identifier forRow: row];
}

Populating method:

- (void) doPopulateTable:exportedTable withTitle: (NSString *) titleString andWord: (NSString *) reportedWord sizingFlag: (NSUInteger) sFlag
{
    NSUInteger size1, size2, size3;
    NSRect tableFrame;

    currentVoice = 1;
    noOfArrays = [exportedTable count];
    if( noOfArrays > 6 )
    {
        switch (currentVoice)
        {
            case 1:
                actuelColDesc = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:0]];
                actuelColSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:1]];
                actuelColPlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:2]];
                reportParseSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:7]];
                reportParsePlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:8]];
                break;
            case 2:
                actuelColDesc = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:0]];
                actuelColSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:3]];
                actuelColPlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:4]];
                reportParseSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:9]];
                reportParsePlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:10]];
                break;
            case 3:
                actuelColDesc = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:0]];
                actuelColSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:5]];
                actuelColPlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:6]];
                reportParseSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:11]];
                reportParsePlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:12]];
                break;
            default:
                break;
        }
    }
    else
    {
        actuelColDesc = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:0]];
        actuelColSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:1]];
        actuelColPlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:2]];
        reportParseSing = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:3]];
        reportParsePlur = [[NSMutableArray alloc] initWithArray:[exportedTable objectAtIndex:4]];
    }
    if( noOfArrays == 14 )
    {
        [btnBaseMiddle setHidden:NO];
        [btnBasePassive setHidden:NO];
    }
    [reportTable reloadData];
    if( sFlag == 2 )
    {
        size1 = 686;
        size2 = 644;
        size3 = 320;
    }
    else
    {
        size1 = 524;
        size2 = 474;
        size3 = 150;
    }
    tableFrame = [[self window] frame];
     tableFrame.size.width = size1;
     [[self window] setFrame:tableFrame display:YES];
     tableFrame = [[self reportTable] frame];
     tableFrame.size.width = size2;
     [[self reportTable] setFrame:tableFrame];
     [[self column1] setWidth:size3];
     [[self window] setTitle:[NSString stringWithString:titleString]];
}

(The run that I'm using for debug has 107 rows - i.e. the arrays each have 107 objects.)

Properties of the TableView include the following: View Based, Floats Group Rows (YES), Trancates Last Visible Line (NO), State Enabled (YES), Autoresizes Subviews (YES).

1
Can you please show in the images that what you need and what you are getting? - shivi_shub
What happens if you return 107 in numberOfRowsInTableView and @"Test" in objectValueForTableColumn ? Do you get any empty cells? - koen
shivi_shub, I tried adding images but Stack Overflow objected. I'll try again: I'm new to Stack Overflow so I may have misunderstood. - Leonard Clark
Strangely, things have kind of moved on. I worked out that it seems to be something to do with the initialisation of the Class: debugging it resulted in some Outlets showing as nil. So I: a) added code to the class initialiser to copy back to AppDelegate self (the class address); b) having initialised the class, my calling code used the passed back address rather than the address returned from the initialisation method. It worked! Why? Who knows? - Leonard Clark
However, that was late in the day. I came back to it this morning to discover that I had populated and showed the window twice, once for each variable I was holding. No matter which of the two I used, when I removed one, something was missing. Bizarre or what? Having restored code to the original, the TableView now works! (Image to follow - I hope). However, some buttons are still showing as nil. The only thing that I can think of is that I did a straight build (without debug). - Leonard Clark

1 Answers

0
votes

Apologies to shiva_shub and Koen for wasting their time: it would seem that some of the objects window controller were not being activated until I show-ed the window. So, once I put the population code after showing the window, all worked fine. I assumed that, since I initialised with nib, all Outlets and Actions would have been instantiated too.

Thanks to my commentators for their help.