Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > OK, what have I...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3770 of 3882
Post > Topic >>

OK, what have I missed??? (continuation of my NSTableView question)

by Don Bruder <dakidd@[EMAIL PROTECTED] > Jun 12, 2008 at 11:19 AM

The CocoaDev site that Reinder pointed me at was *VERY* useful - At 
least now I think I've got the beginnings of a grip on how to use 
NSTableView.

Except for one minor detail...

My view is empty. And I can't figure out why.


Here's my code (some comments added after pasting from project to 
clarify things):
-*-*-*- TableViewController.h
#im****t <Cocoa/Cocoa.h>

@[EMAIL PROTECTED]
 TableViewController : NSObject
{
    IBOutlet NSTableView *myTable;
   @[EMAIL PROTECTED]
 
   NSMutableDictionary *itemList;
   // Arrays for items that will be visible in the table
   NSMutableArray *itemDescriptionArray;
   NSMutableArray *bidCountArray;
   NSMutableArray *currentPriceArray;
   NSMutableArray *****pCostArray;
   NSMutableArray *endTimeArray;
   // Arrays for items that will be needed for other use, but normally 
won't be visible in the table
   NSMutableArray *itemURLArray;
   NSMutableArray *itemNumberArray;
}

// Make addData:forKey: public so that it can be called (indirectly) by 
DataGetter's load:forController: method to stuff the arrays
- (void)addData:(id)theData forKey:(id)key;
@[EMAIL PROTECTED]
 TableViewController.m
#im****t "TableViewController.h"
#im****t "DataGetter.h"

@[EMAIL PROTECTED]
 TableViewController

// Internal use only - Works as planned/expected.
- (NSMutableArray *)createArray
{
   NSMutableArray *newArray;
   
   newArray = [NSMutableArray arrayWithCapacity:0];
   return [newArray retain]; // Any array created here needs to be 
fairly permanent.
}

// Appears to be doing what it should. (See comments at end of method)
-  (void)awakeFromNib
{
   // We're going to need a dictionary...
   itemList = [NSMutableDictionary dictionaryWithCapacity:0];
   [itemList retain]; // We want it to stick around...

   // and arrays to be associated with it...
   // (Yes, I realize I could do it a bit differently. For now, this 
works.)
   itemDescriptionArray = [self createArray];
   bidCountArray = [self createArray];
   currentPriceArray = [self createArray];
   ****pCostArray = [self createArray];
   endTimeArray = [self createArray];
   itemURLArray = [self createArray];
   itemNumberArray = [self createArray];

   // Put the keys/arrays into the dictionary. Again, could be done 
differently.
   [itemList setObject:itemDescriptionArray forKey:@[EMAIL PROTECTED]
"itemDescription"];
   [itemList setObject:bidCountArray forKey:@[EMAIL PROTECTED]
"bidCount"];
   [itemList setObject:currentPriceArray forKey:@[EMAIL PROTECTED]
"currentPrice"];
   [itemList setObject:****pCostArray forKey:@[EMAIL PROTECTED]
"****pCost"];
   [itemList setObject:endTimeArray forKey:@[EMAIL PROTECTED]
"endTime"];
   [itemList setObject:itemURLArray forKey:@[EMAIL PROTECTED]
"itemURL"];
   [itemList setObject:itemNumberArray forKey:@[EMAIL PROTECTED]
"itemNumber"];
   
   // Grab the raw data, and parse it into the arrays
   DataGetter *Getter = [DataGetter new];
   [Getter load:myTable forController:self];
   // (At one point, I thought I'd need "myTable" over in 
load:forController - I ended up not needing anything except this 
object's "self", so passing myTable is pointless now - I just haven't 
got "a round tuit" yet.)

   // Make sure the NSTableView is using the newly read/parsed data.
   [myTable reloadData];

   // Breakpointing to here, then using the debugger to select itemList 
then "Print description to console"
   // shows that everything is precisely as expected - itemList has a 
count of 7, The keys are all correct, 
   // the arrays that hold the values all hold the expected values, in 
the right quantities - EVERYTHING
   // about it is right. But I still get an empty (other than column 
headers, as set up in IB) TableView
   // displayed. What have I missed?
}

// Works as expected/intended. Debugging code (removed now that I've 
verified it's working) showed that the correct count gets returned.
- (int)numberOfRowsInTableView:(NSTableView *)aTable
{
   return [[itemList objectForKey:@[EMAIL PROTECTED]
"itemDescription"] count];
}

// This routine appears to never get called.
// Putting a breakpoint (or several of them) anywhere in it does nothing 
whatsoever. I strongly suspect that this is the reason I'm getting a 
blank NSTableView displayed, but I don't know where to look for the 
problem. If it were to execute, it looks like it *SHOULD* do what it's 
supposed to. But it doesn't seem to get executed, and I don't know why.
- (id)tableView:(NSTableView *)aTable 
objectValueForColumn:(NSTableColumn *)aCol row:(int)aRow
{
   id              loc_id, loc_dat;
   NSMutableArray *loc_col;
   
   loc_id = [aCol identifier];
   if (loc_id != nil)
    {
      loc_col = [itemList objectForKey:loc_id];
      if (loc_col != nil)
       {
         loc_dat = [loc_col objectAtIndex:aRow];
       }
    }
   return (loc_dat);
}

// Internal use only. (via addData:forKey:) Works as planned.
- (void)setTableData:(id)theData forKey:(id)key
{
   [[itemList objectForKey:key] addObject:theData];
}

// Called (indirectly) by DataGetter's load:forController: method to 
stuff the arrays. Works as planned.
- (void)addData:(id)theData forKey:(id)key
{
   [self setTableData:theData forKey:key];
}
@[EMAIL PROTECTED]
 IB, I've got a main window. In it is the NSTableView. The 
NSTableView's "dataSource" outlet is connected to an instance of 
"TableViewController" by dragging the connection line from the view to 
the controller instance. Ditto the "delegate" outlet of the view. (No, 
NOT one of the NSTableColumns embedded in the NSTableView, or the 
NSScrollview the NSTableView is embedded in - I was *VERY* careful about 
that, and it caused me no end of headaches trying to figure out HOW to 
do it! But it got done eventually.)

TableViewController has an outlet - "myTable", connected to the 
NSTableView by dragging *FROM* the controller instance *TO* the 
NSTableView, so I can access the NSTableView over in XCode land. That 
seems to be working right.

But I've still got an empty (although it DOES have the right column 
headers (as set in IB) and sets up the proper number of rows - they're 
just empty) NSTableView displayed.

Obviously, I've missed something, but I'm not figuring out what that 
"something" is. Anybody see anything obvious?

-- 
Don Bruder - dakidd@[EMAIL PROTECTED]
 - If your "From:" address isn't on my
whitelist,
or the subject of the message doesn't contain the exact text
"PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without
my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd>
for more
info
 




 4 Posts in Topic:
OK, what have I missed??? (continuation of my NSTableView questi
Don Bruder <dakidd@[EM  2008-06-12 11:19:43 
Re: OK, what have I missed??? (continuation of my NSTableView qu
Gregory Weston <uce@[E  2008-06-12 15:24:52 
Re: OK, what have I missed??? (continuation of my NSTableView qu
Don Bruder <dakidd@[EM  2008-06-12 14:44:18 
Re: OK, what have I missed??? (continuation of my NSTableView qu
Gregory Weston <uce@[E  2008-06-13 10:41:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 11:04:03 CST 2008.