Re: Doe each NSTableView requires its own controller?
Re: Doe each NSTableView requires its own controller?
- Subject: Re: Doe each NSTableView requires its own controller?
- From: mmalcolm crawford <email@hidden>
- Date: Thu, 29 Jan 2004 12:55:12 -0800
On Jan 29, 2004, at 11:42 AM, M. Uli Kusterer wrote:
At 0:00 Uhr -0800 28.01.2004, mmalcolm crawford wrote:
Most likely scenario: your controller will have two instance
variables (outlets), tableView1 and tableView2. Your controller will
also implement the NSTableView data source and delegate methods. The
first parameter in all of these is the table view sending the
message. Your implementations therefore check which tableview is
sending the message before returning the appropriate value.
e.g.
- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
if (tableView == tableView1)
{
return [array1 count];
}
return [array2 count];
}
That's not a very OO design, though ... I'd personally would consider
it much cleaner if the OP just wrote a generic MyTableViewController
class that talked to a model class. That way, all that's needed would
be a new instance of this controller, hooked up to the model and
another view, and he could have dozens of views into the same data.
Isn't that the main point of OO and MVC?
Well, yes and no. It's always difficult to know exactly what level to
pitch a response, and in many cases the solution I give above will be
easiest, whether or not it's "pure OO". It certainly does to MVC,
since there's still a single controller object.
If I wanted to give what for a beginner would be a more complex
solution to understand, but which is more OO-pure, I'd suggest using
NSArrayControllers...
mmalc
_______________________________________________
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.