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

Re: Beginner Question


  • Subject: Re: Beginner Question
  • From: Craig Bakalian <email@hidden>
  • Date: Sun, 13 Oct 2002 18:35:22 -0400

On Sunday, October 13, 2002, at 03:49 PM,
email@hidden wrote:

>
> I must be misunderstanding something in how the examples work - what
> is the
> "cocoa" way?
>
> Thanks for any tips.
>

Hi Frank,
I am a bit confused by what you want, but I think I can help. Have
you ever programmed in Java? It is very similar to setting up a
tableModel in java. The object or class holding the instance of your
NSMutableArray *myData needs to be connected to the NSTableView as a
dataSource. So, in Interface Builder control drag from the NSTableView
to the class holding the instance of *myData. That NSTableView needs
to be an instance in the class holding *myData, so it can send
[myTableView reloadData] somehow. So, in IB control drag from the
class to the NSTableView and give it a name.
Now you need to code the class holding *myData in Project Builder.
You will need to following in your .h file:

- (int) numberOfRowsInTableView: (NSTableView *)tableView;
- (id) tableView: (NSTableView *)tableView
objectValueForTableColumn: (NSTableColumn *) tableColumn
row: (int)row;
- (id) tableView: (NSTableView *)tableView
setObjectValue: (id)object
forTableColumn: (NSTableColumn *) tableColumn
row: (int)row;

Then you need to implement them in the .m file. Something like below
for I don't know what your up to...

- (id) tableView: (NSTableView *)tableView
setObjectValue: (id) object
forTableColumn: (NSTableColumn *) tableColumn
row: (int)row
{
NSString *identifier = [tableColumn identifier];
Record *rec = [myData objectAtIndex: row];
[myData takeValue: object forKey: identifier];
}

- (id) tableView: (NSTableView *)tableView
objectValueForTableColumn: (NSTableColumn *) tableColumn
row: (int)row
{
NSString *identifier = [tableColumn identifier];
Record *rec = [myData objectAtIndex: row];
return [myData valueForKey: identifier];
}

- (int) numberOfRowsInTableView: (NSTableView *)tableView
{
return [myData count];
}

The tricky part is the [tableColumn identifier] which needs to reflect
the instances contained in Record.h. So, if you have

NSString *name;
NSString *city;
NSString *phoneNum;

declared as instances in Record.h, the table column identifiers of the
NSTableView (that you control dragged the connection from) need to be
name, city, phoneNum. The last thing you gotta do is to set up some
type of action that is going to [myTableView reloadData]. Perhaps a
button click action?


Craig Bakalian
_______________________________________________
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.

  • Prev by Date: Re: dual controllers
  • Next by Date: Outlineview conundrum
  • Previous by thread: Re: Beginner Question
  • Next by thread: Updated dev. documentation
  • Index(es):
    • Date
    • Thread