• 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: filling a TableView with pre-existing data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filling a TableView with pre-existing data


  • Subject: Re: filling a TableView with pre-existing data
  • From: Ondra Cada <email@hidden>
  • Date: Tue, 2 May 2006 02:26:36 +0200

Scott,

On 2.5.2006, at 1:04, Scott Frankel wrote:

I hope my question made sense. I've got an NSTableView that I want to use to display rows of data from a database. I'm using Bindings, KVC-style accessors, and an NSArrayController to manage the model-view data flow. But I'm having trouble turning the spigot on ;) I'm not getting my data rows to display in the tableView.

You have to get your data rows into the array controller. Then (given the binding is right, of course) they will be displayed automatically.


The most promising approach seems to be overriding awakeFromNib: in MyDocument.m. How would I connect the NSArrayController to this layer of the app's controller? Am I barking up the right tree at least?

Presume you can get an NSArray of your data in awakeFromNib:, then it's best place. Presumed the array controller is in the very same NIB, just add


IBOutlet NSArrayController *controller;

into your document instance variables, let IB parse the file (that would add the outlet to File's Owner), connect the outlet in IB to the controller, and add something like

-(void)awakeFromNib {
...
NSArray *myobjects=.....;
NSLog(@"Setting %d objects, should be displayed in the table", [myobjects count]);
[controller setContent:myobjects];
...
}


p.s. I've read Apple's doco on bindings and am following Hillegas' book; so I can create data from scratch in my tableView. Still, how do I load data that already exists into an NSTableView?

Huh? I haven't read Hillegas', but anyroad you display an existing array. The two chunks below are *very roughly* equivalent:


// traditional
@interface ... {
NSArray *array;
}
-(int)numberOfRowsInTableView { return [array count]; }
-tableView:tv objectValueForTableColumn:tc row:(int)r { return [[array objectAtIndex:r] forKey:[tc identifier]]; }
-(void)setObjects:(NSArray*)objs {
array=[objs retain];
[tableView reloadData];
}


// new
@interface ... {
NSArrayController *controller; // presumed bound properly to array and its columns
}
-(void)setObjects:(NSArray*)objs {
[controller setContent:objs];
}
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >filling a TableView with pre-existing data (From: Scott Frankel <email@hidden>)
 >Re: filling a TableView with pre-existing data (From: Scott Frankel <email@hidden>)

  • Prev by Date: Re: Spotlight query operator NOT
  • Next by Date: Re: Is there any overhead on hidden views?
  • Previous by thread: Re: filling a TableView with pre-existing data
  • Next by thread: Re: filling a TableView with pre-existing data
  • Index(es):
    • Date
    • Thread