• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie: two tables on one window, how to talk to them?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Chris Hanson <email@hidden>
  • Date: Mon, 2 Sep 2002 13:00:34 -0500

At 4:44 PM +0100 9/2/02, Keith Pritchard wrote:
Question is, this works when I have one table, when I want to talk to
another, how do I do it? Do I compare TableView somehow to see which
table it's responding to?

Yes, exactly. In your controller object, have an outlet to each table view.

Then, in your table view data source methods, you can just compare the table view passed in to the method with the value of the outlet like so:

- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
int numberOfRows;

if (tableView == _firstTableView) {
numberOfRows = [_firstArray count];
} else if (tableView == _secondTableView) {
numberOfRows = [_secondArray count];
} else {
numberOfRows = 0;
}

return numberOfRows;
}

This is the easy and direct way to do it, though it does introduce a bit more dependency between your view objects and controller objects. You could get fancier and create a separate class, instances of which act as table view data sources and map between a data source (i.e. an array) and your table view.

(The Enterprise Objects Framework had something like this in its EOInterface framework, but alas Apple still hasn't listened to our feedback and brought back EOF for Cocoa...)

Hope this helps.

-- Chris

--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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.

References: 
 >Newbie: two tables on one window, how to talk to them? (From: Keith Pritchard <email@hidden>)

  • Prev by Date: Displaying images in NSView
  • Next by Date: Re: Tracking files the right way
  • Previous by thread: Re: Newbie: two tables on one window, how to talk to them?
  • Next by thread: Re: Newbie: two tables on one window, how to talk to them?
  • Index(es):
    • Date
    • Thread