• 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: Tyler LaGrange <email@hidden>
  • Date: Fri, 11 May 2001 09:50:13 -0400

I have a small sample of adding items to the NSTableView (using Java) that I got to work by messing around a bit last night. Are you beyond that point already or would you find that useful at all? I'm pretty new at this too - and the way I did it seems kinda strange to me - what with having one abstract class and one empty class that implements that abstract class. The point is I have some data showing up. ALSO - mine only has one column for now - but you could probably figure out how to add more with some more HashMaps or something. It's probably a little poorly coded, but hey - it's something to start from. Here are my two classes if you would like to try them out or anything:

//
// groupNSTableData.java
// Cocoa Chat Application
//
// Created by tyler on Thu May 10 2001.
// Copyright (c) 2001 __CompanyName__. All rights reserved.
//

import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
import java.util.HashMap;


public abstract class groupNSTableData implements NSTableView.DataSource
{

private HashMap groupMap = new HashMap();

public int numberOfRowsInTableView(NSTableView tv)
{
return groupMap.size();
}

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

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

public void tableViewSetObjectValueForLocation(NSTableView tv, Object o, NSTableColumn tc, int i)
{
return; // didn't implement this method
}

public boolean tableViewWriteRowsToPasteboard(NSTableView tableView,NSArray rows,NSPasteboard pboard)
{
return false; // didn't implement this method
}

public int tableViewValidateDrop(NSTableView tableView,NSDraggingInfo info,int row,int operation)
{
return 0; // didn't implement this method
}

public boolean tableViewAcceptDrop(NSTableView tableView,NSDraggingInfo info,int row,int operation)
{
return false; // didn't implement this method
}
}



//
// groupData.java
// Cocoa Chat Application
//
// Created by tyler on Thu May 10 2001.
// Copyright (c) 2001 __CompanyName__. All rights reserved.
//

import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;


public class groupData extends groupNSTableData{
public groupData()
{
}

}




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

NSTableView groupsTableView; // some variable in your class matching your interface Builder object
groupNSTableData groupData = new groupData(); // an instance of the class I made

Followed by this somewhere

groupsTableView.setDataSource(groupData);

And then calling this seems to PUT data in the view

addGroup(temp);



good luck. let me know if this helps or if you can see anything that would make this work better...

Tyler


On Thursday, May 10, 2001, at 08:56 PM, William Jamieson wrote:

Hello All!!!

I am building a Cocoa Java application that requires the use and
manipulation of table data. I have created a NSTableView with four columns
(the easy part!!!).

The documentation available tells me (as I understand it) that I need to
create an object to connect to the NSTableView as its DataSource (hence
NSTableView.DataSource) and that this object requires 3 methods (2 if the
table data is not editable). These are:

NumberOfRowsInTableView()
TableViewObjectValueForLocation()
TableViewSetObjectValueForLocation() -- Required for editing data

What I don't understand (in my infinite lack of wisdom) is what kind of
object I can/should connect to the NSTableView as its DataSource. To this
effect I have 5 main questions:

1. Should the DataSource object be a SubClass of NSMutableArray which is an
array of arrays (an array of rows)?

2. Do I need to instantiate the object attached as the NSTableView's
DataSource (whatever kind of object it is)?

3. Can the object connected as the NSTableView's DataSource be my main
controller class for the application?

4. What is the best way to implement the 3 methods mentioned above?

5. Should the dataSource object be the same as the delegate object for the
NSTableView? What are the problems/benefits in doing this?

If anyone has a working knock-up example of a project using a NSTableView
that can handle adding and deleting Table Rows could they please point me to
it so I can pull it apart and see how it ticks?

Thanks again for your time and support

Regards

William Jamieson
Systems Developer

Smart Works Systems
_____________________________________________________________
113 Ferrars St Phone: 03) 9696 6851
Southbank Fax: 03) 9690 0092
VIC 3006 Mobile: 0412 715 735
Australia Email: email@hidden
WWW: http://www.smartworks.com.au/
_____________________________________________________________
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: Newbie Question: NSTableView.DataSource
      • From: mmalcolm crawford <email@hidden>
References: 
 >Newbie Question: NSTableView.DataSource (From: William Jamieson <email@hidden>)

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