• 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: Learning question about NSTableView and NSStrings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Learning question about NSTableView and NSStrings


  • Subject: Re: Learning question about NSTableView and NSStrings
  • From: Ondra Cada <email@hidden>
  • Date: Tue, 31 Jul 2001 22:13:26 +0200

John,

>>>>>> John Tsombakos (JT) wrote at Tue, 31 Jul 2001 10:02:12 -0400:
JT> I'm in the process of getting my head around Cocoa. My
JT> latest test is playing around with the NSTableView. I have a
JT> sample app that has a table view in a window and I have a
JT> data source object created (don't ask my how I figured how
JT> to set that up and wire it up!).

I'd guess you dragged the 'wire' and clicked the "Data Source" outlet in the
Inspector. Though, who knows ;)

JT> In the interface for my data source, I define an array to
JT> hold the data for the table (a one column table)
JT> (NSMutableArray *myArray)
JT> In the data source's awakeFromNib routine, I create the
JT> array and stick some data into it: (first question-is this
JT> the right place to do this?)

Depends on the project and the place the table data actually has there. I
for one would not use awakeFromNib for that, but that's more a personal
opinion than a style.

JT> [[myArray alloc] init];

Ouch, that can't work!

myArray=[[NSMutableArray alloc] init];

is what you probably meant. ("Mutable" so as you can use the following code:)

JT> for (i=0; i<=10; i++)
JT> {
JT> [myArray addObject:@"Hello"]
JT> }

All right, though for such test I guess

myArray=[[NSArray alloc]
initWithObjects:@"Hello",@"John",@"how",@"you",@"are",@"today",@"?",nil];

might be easier and better. Again, just an opinion, nothing more.

JT> (I would like each item to by "Line n" with n being the line
JT> number, but I'm not sure how to set that)

for (i=0;i<10;i++)
[myArray addObject:[NSString stringWithFormat:@"Line %d",i]];

JT> Now, in the tableView:setObjectValue:forTableColumn:row:
JT> routine I do:

..._setObjectValue_... you use to change the data. I guess you meant

- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;

JT> return [myTable objectAtIndex:row];
JT> And in the numberOfRowsInTableView: routine I do:
JT> return [myTable count];

Yep, it's all right.

JT> It sort of works, except only 7 items show up in the table
JT> view!

Does it?!? Seems strange!

Try to send the reloadData message to the table view...

JT> Anyone have any suggestions? One thing I'm working towards
JT> is being able to click on one of the rows to "select" the
JT> table, the be able to hit a key to go to the line that
JT> starts with that letter. (Suggestions?)

Hmmmm, either a subclass of the tableview or some smart delegation might be
needed for that, I guess. I'd have to try to implement it to say more;
hopefully somebody other will help.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc


References: 
 >Learning question about NSTableView and NSStrings (From: "John Tsombakos" <email@hidden>)

  • Prev by Date: RE: Help with BSD structs
  • Next by Date: Setting Tab Stops (again)
  • Previous by thread: Learning question about NSTableView and NSStrings
  • Next by thread: Book recommendations for newbies
  • Index(es):
    • Date
    • Thread