 |
 |
2 NSTableViews, one app
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
I'm trying to get 2 NSTableViews to work in the same application with different data sources. one works fine, despite anomalies such as disconnected outlets and name changes, while the other refuses to work, regardless of said anomalies. I get an error while the program is running that says i need to implement the methods "numberOfRowsInTableView:" and "tableView:objectValueForTableColumn:row:" I have both of these implemented and working for the one NSTableView, and i compensated for the second using an If statement to compare aTableView to each of the possibilities. My methods are as follows:
Code:
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
{
id theRecord;
if (aTableView == filteredTable) {
NSParameterAssert(rowIndex >= 0 && rowIndex < [romsArray count]);
if ([[aTableColumn identifier] isEqual:@"listing"])
return [NSImage imageNamed:@"listing"];
theRecord = [romsArray objectAtIndex:rowIndex];
} else if (aTableView == table) {
NSParameterAssert(rowIndex >= 0 && rowIndex < [dataArray count]);
if ([[aTableColumn identifier] isEqual:@"ROMs"])
return [NSImage imageNamed:@"ROMs"];
theRecord = [dataArray objectAtIndex:rowIndex];
}
return theRecord;
}
and:
Code:
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
if (aTableView == filteredTable) {
return [romsArray count];
} else if (aTableView == table) {
return [dataArray count];
} else {
return nil;
}
}
I should mention that i'm quite new to Cocoa/Obj-C, so if the code is messy, it's because it's the best me and the other guy working on this can do.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2003
Status:
Offline
|
|
You have to make sure that your controller is set as the datasource for both tables. You should use the tag of the tables with a switch statement, instead of the memory location for identification.
|
|
I am now going to tell the computer what he can do with a life-times supply of chocolate.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
except the tables both use different arrays, so they have different data sources. as for using a switch statement to identify them, i'll give it at try.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
The "data source" is your controller object which implements -numberOfRowsInTableView: and -tableView:objectValueForTableColumn:row:, not the array or other model object your data actually comes from.
In the same object which implements those methods, call [table setDataSource:self] and [filteredTable setDataSource:self]. Or hook the tables up to that object in IB.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
Originally posted by Rickster:
The "data source" is your controller object which implements -numberOfRowsInTableView: and -tableView:objectValueForTableColumn:row:, not the array or other model object your data actually comes from.
In the same object which implements those methods, call [table setDataSource:self] and [filteredTable setDataSource:self]. Or hook the tables up to that object in IB.
THANK YOU! it worked! god, we've been agonizing over that all day. and now we can end it knowing we got past that one hurtle...
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|