Re: Newbie: two tables on one window, how to talk to them?
Re: Newbie: two tables on one window, how to talk to them?
- Subject: Re: Newbie: two tables on one window, how to talk to them?
- From: Mark de Jong <email@hidden>
- Date: Mon, 2 Sep 2002 10:39:32 -0700
Keith,
What I've done is simply subclass NSTableView and then, in IB, read in
the headers for these (sub)classes and set the "custom class" property
of each table to be their respective subclasses of NSTableView.
This way, each instance responds to their own callbacks without you
needing to do special checks to determine which table you're in.
In "awakeFromNib" I set up whatever initializations the table needs,
including setting the "delegate" to "self" and the "datasource" to
point to your class that manages the table's data. In my case, I set
that to "self" as well.
In my case, I take this one step farther. My tables (actually, I'm
using NSOutlineView because I need expandable items, but this should
work fine for NSTableView as well) show very similar data with minor
variations. So, I have my "base" table view class that handles all the
common work and then I subclass my other tables off this base class.
Now I can ensure that all the common functionality is the same for each
table (including responding to menu items and toolbar items) and in the
subclasses I override only those methods that differentiate that view
from the base view.
I hope this helps. I also hope it isn't too confusing ... :-)
-- Mark
On Monday, September 2, 2002, at 09:24 AM, Keith Pritchard wrote:
Tony,
On Monday, September 2, 2002, at 04:59 PM, Tony S. Wu wrote:
- (int) numberOfRowsInTableView:(NSTableView *)aTableView
{
if (aTableView == myTableViewOutlet)
// do something
else if (aTableView == mySecondTableViewOutlet)
// do something else
}
Thanks! confirms what I was doing (except for the = rather than ==
typo... too much basic/delphi recently, not enough C.
How does it work for notifications though?
I have
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
NSLog(@"Selected row %i, Group %@",[tableview1 selectedRow],[myArray
objectAtIndex:[tableview1 selectedRow]] );
}
This gets called even if I click a row in tableview2 (but of course
it's showing data from tableview1 as coded above).... How should I be
checking which view sent the notification?
By the way, you don't necessary follow this, better start with capital
letter with class name :D
Like: NewsController.m/h
Cocoa's name convention :)
It's being followed but only in the things that projectbuilder/ib
created ;-) so valid comment, thanks :)
Keith
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.