TableView insanity... please help!!
TableView insanity... please help!!
- Subject: TableView insanity... please help!!
- From: John Draper <email@hidden>
- Date: Tue, 28 Dec 2004 14:13:11 -0800
Hi,
I have a number of issues involving a 3 column table view. Each row
in the table comes from a NSDictionary as a "data source". This almost
always has less then 100 key/value pairs, and is created on a timely basis
(every 30 secs or so), so it don't really matter if it's Mutable or not.
When using a dictionary as a "data source" for a Table View, I'm using
the required callbacks...
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
// if (myUserDict == nil)
// return 0;
return([myUserDict count]);
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
// and I do my code here for each of the 3 columns of the
// table view.
}
Obviously, the "rowIndex", going from (0....count-1) makes it a bit
difficult to reference a row when a dictionary is always referenced
by a key. The order of the information I want displayed in the table
view is not important... so I took a really simple approach to
also keep and maintain an array of keys.
Luckily the NSDictonary has a nice handy method "allKeys" which
generates an array of keys, so I can now reference the keys by index.
So, everytime I create a dictionary, I also create this array of keys
like so...
myIDKeys = [myUserDict allKeys];
Where my "Controller" maintains and manages "myUserDict", and "myIDKeys"
references as instance variables defined as follows.
NSMutableDictionary *myUserDict;
NSArray *myIDKeys;
In my "objectValueForTableColumn" notification callback, I extract for
each row, and column the key like this..
userIDKey = [myIDKeys objectAtIndex:rowIndex];
which gives me the Key into a dictionary of "User" objects, of which
I reference it by...
userObj = [myUserDict valueForKey:userIDKey];
With this 'userObj', depending on the column, I can then return a
NSString value from this 'userObj' for display in the table view.
Which it does quite nicely. No complaints there.
Next, logically, I want to deal with item selection in the table view,
so I dutifully define and post a notification in my "awakeFromNib"
like so...
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(tableViewSelectionDidChange:)
name:NSTableViewSelectionDidChangeNotification
object:nil];
Then define a method in my "controller" like this...
- (void)tableViewSelectionDidChange: (NSNotification *) notification
{
// without boring you with details, I do the following..
if (myUserDict == nil)
return; // because my Dict may not be created yet
row = [usersTableView selectedRow]; // get the new selected row.
selectedUser = [myUserDict objectForKey:myKey]; // Get my selected
user object
// 'selectedUser' is an instance variable in my "controller".
}
THE PROBLEM - and associated questions.
---------------------------------------
I traced through ALL of the code in "objectValueForTableColumn" and my
callbacks
go to completion for this routine. No apparent object de-allocation at
this stage.
But after that, although the Table View is populated with the proper data,
the selection is "grey" instead of "blue" color.
But the instant I try and select the table view, I get a SIG 11 alert.
Which
after checking it's meaning, indicates that something has gotten
de-allocated.
I'm clueless what it is... for instance, when I do...
myIDKeys = [myUserDict allKeys];
to make my array of keys, I set my instance variable to point to it.
Should I do...
myIDKeys = [[myUserDict allKeys] retain];
I've originally assumed that when this returns an array, I can now have
control
over it and keep it for whatever.
Of course I tried the above, with slightly different behavior.
I put a -[NSException raise] as a breakpoint, and got this.... when I
selected
an item in the TableView.
#0 0x908311f4 in objc_msgSend
#1 0x00470724 in -[Controller
tableView:objectValueForTableColumn:row:] at Controller.m:1116
#2 0x92e7de1c in -[NSTableView mouseDown:]
#3 0x92e02c60 in -[NSWindow sendEvent:]
#4 0x92df5324 in -[NSApplication sendEvent:]
#5 0x92dfd73c in -[NSApplication run]
#6 0x92eb9b80 in NSApplicationMain
#7 0x000d9f74 in main at main.m:13
0x908311e0 <+0000> cmplwi r3,0
0x908311e4 <+0004> beq- 0x90831308 <objc_msgSend+296>
0x908311e8 <+0008> lwz r12,0(r3)
0x908311ec <+0012> lwz r12,32(r12)
0x908311f0 <+0016> stw r9,48(r1)
0x908311f4 <+0020> lwz r11,0(r12) <---- it stops here.
0x908311f8 <+0024> addi r9,r12,8
0x908311fc <+0028> rlwinm r11,r11,2,0,29
It appears that something (God knows what) is being de-allocated before
being used. I have NO IDEA what it is.... nor do I have any plan or means
to find out, since it calls some internal Apple code, which of course
I have
NO source code for.
Then I tried it again, this time retaining the array if keys like so...
myIDKeys = [[myUserDict allKeys] retain];
I started the program again, TableView populates properly, but when I
click
in the tableview, the program hangs up, and even the debugger looses
control
and I have to force quit.... When I do, I get this...
#0 0x9083120c in objc_msgSend
#1 0x92e7de30 in -[NSTableView mouseDown:]
#2 0x92e02c60 in -[NSWindow sendEvent:]
#3 0x92df5324 in -[NSApplication sendEvent:]
#4 0x92dfd73c in -[NSApplication run]
#5 0x92eb9b80 in NSApplicationMain
#6 0x000d9f74 in main at main.m:13
And it breaks here...
0x908311e0 <+0000> cmplwi r3,0
0x908311e4 <+0004> beq- 0x90831308 <objc_msgSend+296>
0x908311e8 <+0008> lwz r12,0(r3)
0x908311ec <+0012> lwz r12,32(r12)
0x908311f0 <+0016> stw r9,48(r1)
0x908311f4 <+0020> lwz r11,0(r12)
0x908311f8 <+0024> addi r9,r12,8
0x908311fc <+0028> rlwinm r11,r11,2,0,29
0x90831200 <+0032> and r12,r4,r11
0x90831204 <+0036> lwzx r2,r9,r12
0x90831208 <+0040> addi r12,r12,4
0x9083120c <+0044> cmplwi r2,0 <---- BREAKS HERE.
0x90831210 <+0048> beq- 0x90831234 <objc_msgSend+84>
0x90831214 <+0052> lwz r0,0(r2)
So this DOES make SOME difference.
I hope I included everything needed for someone to show me what I'm doing
wrong.
I'm about ready to use one of my instances of support from Apple if I cannot
get any resolution from the list. I've already been working on this
problem
for 3 weeks, but I set it aside and did something else, but now I'm
ready to
re-address this problem again.
Has anyone had experience with Apple's Support system? What is the turn
around from the time I submit this and the time I get back any reply.
I COULD get approval to send my project to Apple, but I'm sure I would
get killed if I sent the project to anyone on the Cocoadev list.
Does ANYONE know what's going on?
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden