On Jul 6, 2009, at 8:20 PM, Brian Hughes wrote:

I really appreciate your other points about my error code -- I never thought about what the tableView might do if -1 was returned and now that I think about it I don't really want to find out so I changed it to 0.

Others have already given you a lot of good advice about your general approach to handling the data source for your tables. I just want to comment on your reply here. I may be wrong, but it still sounds like you're not quite sure how data sources work since you casually decided to change the return value for the error case from -1 to 0 (even though that may, in fact, be the best value). What I was getting at in my reply is to determine what it -means- when that "error" case occurs. Is it because you hit that case and don't know why you got there?

My read of your code is that currentIndex_ refers to a particular player in a list and that your table is displaying game scores for that player. I would expect the only times that currentIndex_ would be negative, then, would be that no players have been added to playersArray and/or there are players but none has been selected in some other part of your UI. In that case, your "error" case isn't an error at all but rather an expected situation.

As others have suggested, you should understand how - numberOfRowsInTableView: works: it tells the NSTableView how many rows of real data it contains, not how many rows of the table should be displayed in the UI. The latter is determined by the physical layout of the table in IB as well as any resizing restrictions you put on the table when, say, the window is grown/shrunk.

HTH,
steve


CC: cocoa-dev@lists.apple.com
From: puns...@mac.com
Subject: Re: TableView displaying a zillion empty rows
Date: Mon, 6 Jul 2009 12:32:38 -0700
To: brian5hug...@hotmail.com

On Jul 6, 2009, at 11:50 AM, Greg Guerin wrote:

Brian Hughes wrote:

-(int) numberOfRowsInTableView: (NSTableView *)aTableView
 {
   int returnValue;

   if (aTableView == gameScoresTableView) //This works as expected
   {
      if (currentIndex_>= 0)
      {
         LNPlayer *currentPlayer = [playersArray objectAtIndex:
         currentIndex_];
         NSMutableArray *tempGameRecordsArray = [NSMutableArray
         arrayWithArray: [currentPlayer gameRecordsArray]];
         returnValue = [tempGameRecordsArray count];
      }
      else
      {
         NSBeep ();
NSLog (@"ERROR in LNAppController -- numberOfRowsInTableView:");
         return -1;
      }

    }
else if (aTableView == playerManagementTableView) //This is the one that doesn't work
    {
returnValue = [playersArray count]; //[playersArray count] = 22 NSLog (@"playersArray count = %d", returnValue); // returnValue = 22
    }

return returnValue; //However if I change this to: return returnValue = 22 it works fine!
 }

>What will returnValue be if aTableView is neither gameScoresTableView nor playerManagementTableView? Looks like an uninitialized local variable.
>
> Also, for your error case (table is gameScoresTableView and currentIndex_ is negative), is that a situation you should allow to happen or is that something that could be handled better/ differently by the underlying model or within your controller? What does NSTableView do when you tell it there are -1 rows?
>
> steve
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to