Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > 2 NSTableViews, one app

2 NSTableViews, one app
Thread Tools
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jun 30, 2003, 07:48 PM
 
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
Reply With Quote
Jun 30, 2003, 08:43 PM
 
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
Reply With Quote
Jun 30, 2003, 08:53 PM
 
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
Reply With Quote
Jun 30, 2003, 09:50 PM
 
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.
Rick Roe
icons.cx | weblog
     
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jun 30, 2003, 11:29 PM
 
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...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:45 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2