Re: Multiple NSTableView question
Re: Multiple NSTableView question
- Subject: Re: Multiple NSTableView question
- From: Greg Titus <email@hidden>
- Date: Wed, 20 Jun 2001 23:02:12 -0700
On Wednesday, June 20, 2001, at 03:53 PM, Jason Brown wrote:
>
I keep reading that by evaluating the theTableView argument used in
>
>
- (int)numberOfRowsInTableView:(NSTable *)theTableView
[...]
>
you can distinguish which table view is invoking these methods, when
>
using more than one table view.
>
>
My question is this: Evaluate it against what? What can I do with
>
that argument to figure out which table view is making the given
>
calls? With the second method, I know I can just query the theColumn
>
argument, assuming none of my tables have columns with the same name.
>
But there has to be a better solution that would also work for
>
numberOfRowsInTableView.
Hi Jason,
The usual way would be for your delegate to have outlets for each of the
table views it is interested in which you connect to the table views in
Interface Builder. Then in your delegate method, just compare the table
view passed in the delegate message with the ones in your instance
variables. Like so:
@interface MyTableDelegate : NSObject
{
IBOutlet NSTableView *firstTableView;
IBOutlet NSTableView *secondTableView;
}
@end
@implementation MyTableDelegate
- (int)numberOfRowsInTableView:(NSTableView *)theTableView
{
if (theTableView == firstTableView)
return 1;
else if (theTableView == secondTableView)
return 2;
else
return 0; // something wrong here...
}
...
@end
Hope this helps,
--Greg