Re: NSTableView questions
Re: NSTableView questions
- Subject: Re: NSTableView questions
- From: Chris Williams <email@hidden>
- Date: Fri, 05 Oct 2007 09:58:59 -0700
- Thread-topic: NSTableView questions
You're missing a crucial point: The table view doesn't know squat about your
data -- it asks your delegate.
So, in answer to your queries:
- it's OK that it returns zero at some point, because there's nothing there
at that point. It's only logical.
- yes, applicationDidFinishLaunching is the appropriate place to do
initialization many times because you can't predict when things will get
pulled from the nib, and you, many times, need everything out of the nib to
get the job done. So awakeFromNib doesn't cut it. You have to wait until
later.
- yes, every time you change your data storage underneath the NSTableView
you have to do some form of reload to tell it that things are different.
You don't have to reload the whole thing, look into reloadItem if you just
change one (or a few things).
- You get a reference to the NSTableView by declaring a variable as such:
(IBOutlet) NSTableView *myTable;
and connecting it in the Interface Builder. It isn't unreasonable to
declare this as an Extern even, and reference it from several code modules.
HTH,
Chris
On 10/5/07 9:36 AM, "Hrishikesh Muruk" <email@hidden> wrote:
> I tried using the -applicationDidFinishLaunching: delegate but that
> does not work quite as I expected.
>
> Let me explain what I am trying to do again -
> I have a list of items that are created dynamically. This list
> (dataSrc) has to be displayed in an NSTableView. To show the list in
> the table view I have also implemented the following delegates
> 1. - (int)numberOfRowsInTableView:(NSTableView *) aTable
> 2. - (id)tableView:(NSTableView*) aTable objectValueForTableColumn:
> (NSTableColumn *)
>
>
> When the application is run -numberOfRowsInTableView: is called
> before -applicationDidFinishLaunching: . So initializing the array in
> -applicationDidFinishLaunching: does not work because -
> numberOfRowsInTableView: returns zero (size of array) and the table
> does not get updated after that.
>
> I want to dynamically change the contents displayed in the
> NSTableView. I suppose sending a -reload: message (every time I
> update the contents o the dataSrc array) to the table will work. But
> in my program how do I get a reference to the NSTableView in my program?
>
> Thanks
> Hrishi
>
> On 25-Sep-07, at 11:29 PM, I. Savant wrote:
>
>> On 9/25/07, I. Savant <email@hidden> wrote:
>>>> set up the data source array in the initialization of your
>>>> controlling
>>>> object. so if you have AppController with an NSMutableArray
>>>> property you
>>>> would setup initialize / setup the data source array in
>>>> AppControllers
>>>> init. i guess this assumes you have AppController instantiated
>>>> in your nib
>>>> file
>>
>> As a followup:
>>
>> http://developer.apple.com/documentation/Cocoa/Reference/
>> ApplicationKit/Protocols/NSNibAwaking_Protocol/Reference/
>> Reference.html
>>
>> "Because the order in which objects are instantiated from an archive
>> is not guaranteed, your initialization methods should not send
>> messages to other objects in the hierarchy. Messages to other objects
>> can be sent safely from within awakeFromNib‹by which time it's assured
>> that all the objects are unarchived and initialized (though not
>> necessarily awakened, of course)."
>>
>> --
>> I.S.
>
> ---
> www.greenwaysroad.com
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden