Re: TableView displaying a zillion empty rows Problem Solved!

2009-07-09 Thread Brian Hughes

I really appreciate all the help, it kept me searching for an answer.  Ron 
Fleckner was the closest to diagnosing the problem. I had plugged the unit 
into the wall socket but I forgot to turn the breaker back on.  I had failed 
to call reloadData.  Sorry Andy, I didn't find the answer in the beer bottle.
Dumb, Dumb, Dumb.
Brian
_
Hotmail® has ever-growing storage! Don’t worry about storage limits. 
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009___

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


Re: TableView displaying a zillion empty rows Problem Solved!

2009-07-09 Thread Andy Lee
Argh, when I think of all the times reloadData has been the *first*  
suggestion from the list in response to an NSTableView problem!


Thanks for keeping us posted. :)

--Andy

On Jul 9, 2009, at 10:43 PM, Brian Hughes wrote:

I really appreciate all the help, it kept me searching for an  
answer.  Ron Fleckner was the closest to diagnosing the problem. I  
had plugged the unit into the wall socket but I forgot to turn the  
breaker back on.  I had failed to call reloadData.  Sorry Andy, I  
didn't find the answer in the beer bottle.


Dumb, Dumb, Dumb.

Brian

___

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


Re: TableView displaying a zillion empty rows

2009-07-08 Thread Quincey Morris

On Jul 7, 2009, at 22:36, Brian Hughes wrote:


So I changed my code to reflect Quincy Morris's recommendations.
-(int) numberOfRowsInTableView: (NSTableView *)aTableView {if  
(aTableView == gameScoresTableView) //This works as expected {
LNPlayer *currentPlayer = [playersArray objectAtIndex:  
currentIndex_]; NSMutableArray *tempGameRecordsArray =  
[NSMutableArray arrayWithArray: [currentPlayer  
gameRecordsArray]];return [tempGameRecordsArray count];}
else if (aTableView == playerManagementTableView) {NSLog  
(@playersArray count = %d, [playersArray count]);  //[playersArray  
count] = 22return [playersArray count];}	else {NSLog (@Invalid  
table view);return 0;}}
Since I only have two table views in my program the Invalid table  
view is never called.  The first table view gameScoresTableView  
works perfectly.  The playerManagementTableView does not.  I do not  
create the table views progammatically. I use IB. I do not use  
bindings. My delegates are set correctly and are the same for both  
table views.  I don't know enough about programming nor am I  
arrogant enough to think that there is something wrong with  
NSTableView.  I have always thought the error was in my code.  That  
is precisely why I asked for help.  I couldn't seem to figure out  
what to do next.  I have learned more about table views so I  
appreciate all the help.  However it still does not work.  I am  
going to try removing infrastructure and see if I can find the  
problem.  Any other suggestions would be welcome.  If I figure it  
out I will let you know.  Meanwhile I am going to shine that  
streetlight on the bottle of beer on my desk.  Maybe the solution is  
in there.


Don't take it too hard. We do tend to, um, punish people who post  
imprecise problem descriptions on this list, because it's frustrating  
trying to help when we don't know what the problem really is. :)


More punishment coming up ...

You say it still does not work. Let's try to pin down what that  
means. (Yes, you've already said, but the details were a bit different  
each time.) Your window has the malfunctioning NSTableView which is  
set to a view height of how many rows? 9? Of those visible rows, how  
many actually show data (as opposed to being blank filler)? 0? 9?


If your NSTableView is (say) 9 rows high and you see 9 rows of data  
and there is no scroll bar, but the table really has 22 rows, then the  
easiest possible answer is that you accidentally configured the  
NSTableView in IB to hide its vertical scroll bar.


A second possibility is that you've accidentally removed the  
NSTableView from its required enclosing NSScrollView (although I don't  
really know how you'd convince IB to do that).


It *might* be worth deleting the table view from your NIB file and  
recreating it, although that does have a sort of magical hand-waving  
flavor to it.


Another easy thing to try is to set a breakpoint at your data source's  
tableView:objectValueForTableColumn:row: method, and see if it's ever  
called with a row index of (say) 21. If it is, that kind of points to  
a problem in your NIB. If it's not, that really doesn't tell you  
anything much.


If you put the mouse over your table view and roll the scroll wheel up  
and down, does the view scroll? If you click on the last visible row  
to select it, then press the up or down arrow key, does the selection  
stay where it is or does the view scroll or does the selection  
disappear?


Finally, have you checked the console log for error messages? (It's  
easy to forget to look.) Either open the console window in Xcode while  
the app is running (Command-Shift-R by default), or use the Console  
application to look at the system log. Exceptions can often cause apps  
to behave in mysterious, almost magical, ways without actually  
appearing to crash.


You can finish the beer first if you want.


___

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


Re: TableView displaying a zillion empty rows

2009-07-08 Thread Andy Lee

On Jul 8, 2009, at 1:36 AM, Brian Hughes wrote:

So I changed my code to reflect Quincy Morris's recommendations.


Something removed the indentation from your code, so I've re-added it  
below:



-(int) numberOfRowsInTableView: (NSTableView *)aTableView {
if (aTableView == gameScoresTableView) //This works as expected
{
		LNPlayer *currentPlayer = [playersArray objectAtIndex:  
currentIndex_];
		NSMutableArray *tempGameRecordsArray = [NSMutableArray  
arrayWithArray: [currentPlayer gameRecordsArray]];

return [tempGameRecordsArray count];


A side note, not related to your problem: there's no reason to make a  
copy of the gameRecordsArray.  You could say


		NSMutableArray *tempGameRecordsArray = [currentPlayer  
gameRecordsArray];

return [tempGameRecordsArray count];

or simply

return [[currentPlayer gameRecordsArray] count];


}
else if (aTableView == playerManagementTableView)
{
		NSLog (@playersArray count = %d, [playersArray count]);  // 
[playersArray count] = 22

return [playersArray count];
}
else
{
NSLog (@Invalid table view);
return 0;
}
}


There's another part to your code that we haven't seen, which is your  
tableView:objectValueForTableColumn:row: method.  Out of curiosity,  
can you show us that code?  I assume it is similarly structured to  
handle the two table view cases.  If you put an NSLog in the  
playerManagementTableView case, is it not called 22 times?


The results you've described can't be happening, because it seems  
you're doing everything right.  If you want to send me your project  
off-list I'd be happy to try to track down the problem (and treat the  
code as confidential, of course).  These kinds of impossible results  
drive me nuts.


Since I only have two table views in my program the Invalid table  
view is never called.  The first table view gameScoresTableView  
works perfectly.  The playerManagementTableView does not.  I do not  
create the table views progammatically. I use IB. I do not use  
bindings. My delegates are set correctly and are the same for both  
table views.  I don't know enough about programming nor am I  
arrogant enough to think that there is something wrong with  
NSTableView.  I have always thought the error was in my code.  That  
is precisely why I asked for help.  I couldn't seem to figure out  
what to do next.  I have learned more about table views so I  
appreciate all the help.  However it still does not work.  I am  
going to try removing infrastructure and see if I can find the  
problem.  Any other suggestions would be welcome.  If I figure it  
out I will let you know.  Meanwhile I am going to shine that  
streetlight on the bottle of beer on my desk.  Maybe the solution is  
in there.


If it is, let us know.  That would be a welcome breakthrough in  
computer science. :)


--Andy


___

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


Re: TableView displaying a zillion empty rows

2009-07-08 Thread Florian Soenens

Hi Brian,

you seem to only check for gameScoresTableView and  
playerManagementTableView.

Are your Controller outlets actually connected to these 2 NSTableViews?

Regards,
Florian.

On 06 Jul 2009, at 20:14, Brian Hughes wrote:



Hi,
I have two tableViews in my application.  One works perfectly the  
other doesn't.  For both I use a simple data source.
The tableView uses numberOfRowsInTableView: (NSTableView  
*)aTableView to get the number of rows by doing a count of the  
objects in my array.  This number happens to be 22.  When I run the  
program I get a zillion empty rows after my 22 rows of data.   
However if I use the constant 22 as the return value the tableView  
displays 22 rows of my data.  Any idea about what I am doing wrong?

Here is my code:
   -(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!

   }



   -(id) tableView: (NSTableView *) aTableView  
objectValueForTableColumn: (NSTableColumn *) aTableColumn row: (int)  
rowIndex

   {
  id returnValue = nil;

  if (aTableView == gameScoresTableView)
  {
		LNPlayer *currentPlayer = [playersArray objectAtIndex:  
currentIndex_];
		NSMutableArray *tempGameRecordsArray = [NSMutableArray  
arrayWithArray: [currentPlayer gameRecordsArray]];


id theRecord, theValue;

theRecord = [tempGameRecordsArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];

returnValue = theValue;
  }
  else if (aTableView == playerManagementTableView)
  {
//Which Player?
LNPlayer *player = [playersArray objectAtIndex: rowIndex];
//What is the value of the attribute named identifier?
//returnValue = [player valueForKey: [aTableColumn identifier]];
if ([[aTableColumn identifier] isEqualTo: @firstName_] == YES)
returnValue = [player firstName_];
else if ([[aTableColumn identifier] isEqualTo: @lastName_])
returnValue = [player lastName_];
else if ([[aTableColumn identifier] isEqualTo: @playerName_])
returnValue = [player playerName_];
		else if ([[aTableColumn identifier] isEqualTo:  
@trebleClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
trebleClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@altoClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
altoClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@tenorClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
tenorClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@bassClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
bassClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@symbolTextConcentrationGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
symbolTextConcentrationGameLevel_]];

  }

 return returnValue;
   }
Any help would be much appreciated.
Thanks,
Brian

Than
_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___

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/florian.soenens%40nss.be

This email sent to florian.soen...@nss.be




Looking for Web-to-Print Solutions?
Visit our website :   http://www.vit2print.com


This e-mail, and any attachments thereto, is 

Re: TableView displaying a zillion empty rows

2009-07-08 Thread Andy Lee
  -(id) tableView: (NSTableView *) aTableView  
objectValueForTableColumn: (NSTableColumn *) aTableColumn row:  
(int) rowIndex

  {
  id returnValue = nil;

  if (aTableView == gameScoresTableView)
  {
		LNPlayer *currentPlayer = [playersArray objectAtIndex:  
currentIndex_];
		NSMutableArray *tempGameRecordsArray = [NSMutableArray  
arrayWithArray: [currentPlayer gameRecordsArray]];


id theRecord, theValue;

theRecord = [tempGameRecordsArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];

returnValue = theValue;
  }
  else if (aTableView == playerManagementTableView)
  {
//Which Player?
LNPlayer *player = [playersArray objectAtIndex: rowIndex];
//What is the value of the attribute named identifier?
//returnValue = [player valueForKey: [aTableColumn identifier]];
if ([[aTableColumn identifier] isEqualTo: @firstName_] == YES)
returnValue = [player firstName_];
else if ([[aTableColumn identifier] isEqualTo: @lastName_])
returnValue = [player lastName_];
else if ([[aTableColumn identifier] isEqualTo: @playerName_])
returnValue = [player playerName_];
		else if ([[aTableColumn identifier] isEqualTo:  
@trebleClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
trebleClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@altoClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
altoClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@tenorClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
tenorClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@bassClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
bassClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@symbolTextConcentrationGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
symbolTextConcentrationGameLevel_]];

  }

 return returnValue;
  }


Whoops, I didn't notice until Florian's message that you *did* post  
this code.  If your table columns don't have the right identifiers,  
tableView:objectValueForTableColumn:row: returns nil, which results in  
an empty cell.  So, to echo Quincy's question, what exactly does not  
work?  Is your table displaying *empty* rows, or *no* rows?  Is it  
possible your table columns aren't named what you think they are?


--Andy

___

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


Re: TableView displaying a zillion empty rows

2009-07-08 Thread Quincey Morris

On Jul 8, 2009, at 00:31, Andy Lee wrote:


//returnValue = [player valueForKey: [aTableColumn identifier]];
if ([[aTableColumn identifier] isEqualTo: @firstName_] == YES)
returnValue = [player firstName_];
else if ([[aTableColumn identifier] isEqualTo: @lastName_])
returnValue = [player lastName_];
else if ([[aTableColumn identifier] isEqualTo: @playerName_])
returnValue = [player playerName_];
		else if ([[aTableColumn identifier] isEqualTo:  
@trebleClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
trebleClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@altoClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
altoClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@tenorClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
tenorClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@bassClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
bassClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@symbolTextConcentrationGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
symbolTextConcentrationGameLevel_]];


Incidentally, like in the other delegate method, an else {...handle  
the error...} would be a useful addition on the end of this. Without  
it, it's exactly equivalent to the commented-out valueForKey version.


Also, 'isEqualTo:' is the wrong method to use. It should be  
'isEqualToString:' or possibly 'isEqual:'.



___

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


Re: TableView displaying a zillion empty rows

2009-07-08 Thread Mac First


On Jul 8, 2009, at 12:31 AM, Andy Lee wrote:


if ([[aTableColumn identifier] isEqualTo: @firstName_] == YES)
returnValue = [player firstName_];
else if ([[aTableColumn identifier] isEqualTo: @lastName_])
returnValue = [player lastName_];
else if ([[aTableColumn identifier] isEqualTo: @playerName_])
returnValue = [player playerName_];
		else if ([[aTableColumn identifier] isEqualTo:  
@trebleClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
trebleClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@altoClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
altoClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@tenorClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
tenorClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@bassClefGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
bassClefGameLevel_]];
		else if ([[aTableColumn identifier] isEqualTo:  
@symbolTextConcentrationGameLevel_])
			returnValue = [NSNumber numberWithInt: [player  
symbolTextConcentrationGameLevel_]];


Missing lines:
else
   NSAssert1(@Unknown tablecolumn ID: %@,  
[aTableColumn identifier]);



If you're getting a zillion empty rows, I'll bet you a dollar it's  
because your program SAYS TO DISPLAY a zillion empty rows.  One way to  
do that is to return returnvalue when returnvalue is nil.


Try poking around the rest of your code for potential invalid  
assumptions, too.  Assert is your friend!


--
A Mac person says I want complete control.
A Unix person says no you don't.

___

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


RE: TableView displaying a zillion empty rows

2009-07-07 Thread Brian Hughes


 
 Yet clearly later in the method returnValue is set to 22 via count  
 method applied to my array.  In my debugger and in my NSLogs  
 returnValue is 22.
 
 But you are only logging the case where it does return 22, so what  
 would you expect? Instead, try moving the NSLog to log the *actual*  
 return value just before you return it. I bet you will see plenty of  
 0s going out.
 
 If at the beginning of the method I initailize returnValue to 22 all  
 looks as expected.  Also if at the end of the method I statically  
 set returnValue to 22 all is well.  It just doesn't seem to work if  
 I set returnValue by using:
 returnValue = [playersArray count]; (debugger and NSLog confirm that  
 returnValue is set to 22)
 I don't understand why?
 
 Because clearly there are two main pathways through this code but  
 you're only logging one of them. The other pathway is what's causing  
 the problem but isn't being logged, so you are not seeing its effects.
 
 Also, in the debugger you can set a conditional breakpoint at the last  
 line on returnValue == 0. When it breaks, look at aTableView - it  
 will be something other than the two you're expecting. Debug  
 accordingly.
 
 --Graham
 
 

Hi Graham,
Thanks for your help.  I put an NSLog for returnValue on the line before 
return.  I also put a conditional breakpoint on return to break if returnValue 
== 0.  The NSLog confirmed that returnValue was indeed set to 22.  The 
conditional breakpoint did not break yet my tableView still responds as if 
returnValue = 0.  Just to make certain that I didn't screw up my conditional 
breakpoint I reset it to break if returnValue =22.  It did break.  Maddening!
As I debug I can clearly see that the program is not going through the other 
path.  It is definitely traveling through the path that I am logging.  
Everything says that returnValue is 22 except the actual tableView.  By the way 
when the program does use the other path everything works fine.  So there is 
something about my code in here:
-   (int) numberOfRowsInTableView: (NSTableView *)aTableView{   unsigned int 
returnValue = 0;   if (aTableView == gameScoresTableView) //This works 
as expected {   if (currentIndex_= 0)  {   
LNPlayer *currentPlayer = [playersArray objectAtIndex: currentIndex_];  
NSMutableArray *tempGameRecordsArray = [NSMutableArray 
arrayWithArray: [currentPlayer gameRecordsArray]];   
returnValue = [tempGameRecordsArray count]; NSLog 
(@returnValue = %d, returnValue);  //NSLog prints returnValue = 22; 
  }   else{   NSBeep ();
  NSLog (@ERROR in LNAppController -- numberOfRowsInTableView:);  
  return 0;   }   }   else 
if (aTableView == playerManagementTableView) //This is the one that doesn't 
work   {   returnValue = [playersArray count];  //[playersArray 
count] = 22NSLog (@playersArray count = %d, returnValue);  
//returnValue = 22NSLog (@returnValue = %d, returnValue);  
//NSLog prints returnValue = 22;   }   NSLog 
(@returnValue = %d, returnValue);  //NSLog prints returnValue = 22; 
  return returnValue;  //Conditional breakpoint set to returnValue == 0 does 
not break.  But a conditional breakpoint set to returnValue == 22 does break!} 
that is wrong but I can't figure out what it is.
Also if on the first line I don't initialize returnValue to 0 I get my zillion 
rows.  The NSLog just before return still says returnValue = 22.
Brian

_
Insert movie times and more without leaving Hotmail®. 
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009___

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


Re: TableView displaying a zillion empty rows

2009-07-07 Thread Quincey Morris

On Jul 7, 2009, at 09:35, Brian Hughes wrote:

As I debug I can clearly see that the program is not going through  
the other path.  It is definitely traveling through the path that I  
am logging.  Everything says that returnValue is 22 except the  
actual tableView.  By the way when the program does use the other  
path everything works fine.  So there is something about my code in  
here:


You're flailing around here. It's time for your to get your thinking  
cap on. :)


First of all, I assure you that table views and their data sources  
work fine, in the way that they're documented to work. Almost  
certainly, if something goes wrong like this, (a) it's not a magical  
happening, and (b) there's something wrong with your code, somewhere,  
or with your NIB file. If you can't find anything wrong with your  
numberOfRowsInTableView: data source method, it's probable that the  
problem is elsewhere.


Second, you seem uncertain about what your data source is a data  
source for. Is it a data source for exactly two specific table views,  
or for those two plus an indeterminate number of others? If exactly  
two, then the most appropriate pattern (given that you're having  
problems) would be:


- (NSInteger) numberOfRowsInTableView: (NSTableView*) aTableView {
if (aTableView == table1) {
...
return numberOfTable1Rows;
}
else if (aTableView == table2) {
...
return numberOfTable2Rows;
}
else {
			NSLog (@Invalid table view); // bonus points for throwing an  
exception here

return 0;
}

and set a breakpoint on the NSLog statement to catch the error  
condition.


Third, everything you've described so far suggests that you actually  
have more than 2 tables using this data source method, AND/OR the  
table you're looking at in your window isn't one of these two. So, you  
need to actually find out. If you are creating table views (or setting  
their delegates and data sources) via code, you need to scrutinize  
that code. If you're setting them up in a NIB file, you need to  
scrutinize the view hierarchy and connections. If you're using  
bindings to provide any content to your table views, you need to make  
sure they're correct. If you're using a combination of those  
techniques, then you're going to have to look carefully for unwanted  
interactions. You may have to simplify the problem by *removing* some  
of this infrastructure, then adding it back in a controlled manner.


If the problem you're having isn't in the code you're looking at, look  
elsewhere. There's more light under the streetlamp, but that may not  
be where you dropped your nickel.



___

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


Re: TableView displaying a zillion empty rows

2009-07-07 Thread Steve Christensen

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


RE: TableView displaying a zillion empty rows

2009-07-07 Thread Brian Hughes

So I changed my code to reflect Quincy Morris's recommendations.
-(int) numberOfRowsInTableView: (NSTableView *)aTableView {if (aTableView == 
gameScoresTableView) //This works as expected {
LNPlayer *currentPlayer = [playersArray objectAtIndex: currentIndex_]; 
NSMutableArray *tempGameRecordsArray = [NSMutableArray arrayWithArray: 
[currentPlayer gameRecordsArray]];return [tempGameRecordsArray count];}
else if (aTableView == playerManagementTableView) {NSLog (@playersArray count 
= %d, [playersArray count]);  //[playersArray count] = 22return [playersArray 
count];}  else {NSLog (@Invalid table view);return 0;}}
Since I only have two table views in my program the Invalid table view is 
never called.  The first table view gameScoresTableView works perfectly.  The 
playerManagementTableView does not.  I do not create the table views 
progammatically. I use IB. I do not use bindings. My delegates are set 
correctly and are the same for both table views.  I don't know enough about 
programming nor am I arrogant enough to think that there is something wrong 
with NSTableView.  I have always thought the error was in my code.  That is 
precisely why I asked for help.  I couldn't seem to figure out what to do next. 
 I have learned more about table views so I appreciate all the help.  However 
it still does not work.  I am going to try removing infrastructure and see if I 
can find the problem.  Any other suggestions would be welcome.  If I figure it 
out I will let you know.  Meanwhile I am going to shine that streetlight on the 
bottle of beer on my desk.  Maybe the solution is in there.
}


_
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290___

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


Re: TableView displaying a zillion empty rows

2009-07-06 Thread Greg Guerin

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.

  -- GG

___

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


Re: TableView displaying a zillion empty rows

2009-07-06 Thread Steve Christensen

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


RE: TableView displaying a zillion empty rows

2009-07-06 Thread Brian Hughes

Hi Steve, 

Thanks for your help.  You were right it is acting like an unintialized local 
variable.  However when I initialize returnValue to 0 at the beginning of the 
method. 
int returnValue = 0;
I got some new bizarre behavior. In Interface Builder the tableView is set to 
show 9 rows.  Now, with returnValue initialized to 0, when I run the 
application the tableView no longer has a zillion extra rows which is good. 
Rather it only has 9.  No vertical scroll to see the other 13 rows of data.  
Now the tableView is behaving as if I have zero rows.  Yet clearly later in the 
method returnValue is set to 22 via count method applied to my array.  In my 
debugger and in my NSLogs returnValue is 22.  
If at the beginning of the method I initailize returnValue to 22 all looks as 
expected.  Also if at the end of the method I statically set returnValue to 22 
all is well.  It just doesn't seem to work if I set returnValue by using:
returnValue = [playersArray count]; (debugger and NSLog confirm that 
returnValue is set to 22)
I don't understand why?

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.
Thanks,
Brian
CC: cocoa-...@lists.apple.comfrom: 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
 

_
Windows Live™: Keep your life in sync. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_BR_life_in_synch_062009___

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


Re: TableView displaying a zillion empty rows

2009-07-06 Thread Graham Cox


On 07/07/2009, at 1:20 PM, Brian Hughes wrote:

Thanks for your help.  You were right it is acting like an  
unintialized local variable.  However when I initialize returnValue  
to 0 at the beginning of the method.

int returnValue = 0;
I got some new bizarre behavior. In Interface Builder the tableView  
is set to show 9 rows.


Bear in mind that only your data source actually sets the number of  
rows. The number of rows apparently visible in IB is just how it is  
displayed - there are 0 rows, not 9.


Now, with returnValue initialized to 0, when I run the application  
the tableView no longer has a zillion extra rows which is good.  
Rather it only has 9.


No, it has 0.

No vertical scroll to see the other 13 rows of data.  Now the  
tableView is behaving as if I have zero rows.


Because it does have 0 rows.

Yet clearly later in the method returnValue is set to 22 via count  
method applied to my array.  In my debugger and in my NSLogs  
returnValue is 22.


But you are only logging the case where it does return 22, so what  
would you expect? Instead, try moving the NSLog to log the *actual*  
return value just before you return it. I bet you will see plenty of  
0s going out.


If at the beginning of the method I initailize returnValue to 22 all  
looks as expected.  Also if at the end of the method I statically  
set returnValue to 22 all is well.  It just doesn't seem to work if  
I set returnValue by using:
returnValue = [playersArray count]; (debugger and NSLog confirm that  
returnValue is set to 22)

I don't understand why?


Because clearly there are two main pathways through this code but  
you're only logging one of them. The other pathway is what's causing  
the problem but isn't being logged, so you are not seeing its effects.


Also, in the debugger you can set a conditional breakpoint at the last  
line on returnValue == 0. When it breaks, look at aTableView - it  
will be something other than the two you're expecting. Debug  
accordingly.


--Graham


___

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