• 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 Question: NSTableView.DataSource
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Question: NSTableView.DataSource


  • Subject: Re: Newbie Question: NSTableView.DataSource
  • From: mmalcolm crawford <email@hidden>
  • Date: Fri, 11 May 2001 16:40:48 +0100

Tyler LaGrange wrote:

This is misleading in a couple of significant ways:

public abstract class groupNSTableData implements NSTableView.DataSource

There is no need to implement the NSTableView.DataSource interface.
Objects with delegates use introspection to discover what methods the delegate implements, and only call those.

private HashMap groupMap = new HashMap();

I'm not sure why you're using a HashMap rather then, say, a Vector, or better still an NSMutableArray? The goal of a table view is to display an ordered collection of elements. Putting the elements into a hash table with string keys "1", "2", "3", etc. seems "unusual". I suspect you'll run into interesting problems if you try to remove elements...

public void addGroup(String _name)
{
groupMap.put(Integer.toString(groupMap.size()),_name);
}

You may want to inform the table view that its contents have changed:

tableView.reloadData();
tableView.selectRow(row, false);
tableView.scrollRowToVisible(row);

or possibly just:
tableView.noteNumberOfRowsChanged();

public Object tableViewObjectValueForLocation(NSTableView tv, NSTableColumn tc, int i)
{
return groupMap.get(Integer.toString(i));
}

This is fine for a table displaying one column, but it won't scale to multiple columns.
The way that this works "best" is if your elements inherit from NSObject, so you can take advantage of key-value coding:

String identifier = (String)tc.identifier();
NSObject nso = (NSObject)aNSMutableArray().objectAtIndex(row);
return nso.valueForKey(identifier);

AND - then in your Controller class you would have this:

It is often the case that the Controller and data source are the same object.

mmalc


  • Follow-Ups:
    • Re: Newbie Question: NSTableView.DataSource
      • From: Tyler LaGrange <email@hidden>
References: 
 >Re: Newbie Question: NSTableView.DataSource (From: Tyler LaGrange <email@hidden>)

  • Prev by Date: Re: FW: Objective C vs. Java
  • Next by Date: Re: Newbie Question: NSTableView.DataSource
  • Previous by thread: Re: Newbie Question: NSTableView.DataSource
  • Next by thread: Re: Newbie Question: NSTableView.DataSource
  • Index(es):
    • Date
    • Thread