Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java Cocoa Table View DataSources



Welcome to the impedance mismatch between reference counting and garbage collection.

A table's dataSource is a weak reference. The table does not retain it. For various extremely subtle and obscure reasons deep in the Java bridge, this means that if your pure Java dataSource is not retained by some other Obj-C object, it will ultimately be collected and disappear (actually it is the Obj-C proxy to the Java object that disappears).

The easiest thing to do is to simply shove the dataSource into an NSArray that you keep around.

Nasty and brutish, but there it it is.

Mike


Begin forwarded message:

From: Niko Matsakis <email@hidden>
Date: Sat Dec 28, 2002 11:48:14 AM US/Pacific
To: email@hidden
Subject: Java Cocoa Table View DataSources

I'm having some trouble with cocoa table view datasources. When I call
"mTableView.setDataSource (new ListSource (stringarray))", it seems to work
for a while but eventually crashes.

If there is a better place to go for help with Java Cocoa, let me know. I've
got some other questions about dynamically generating the widgets in the
window.

Here is the data view class:

//
// ListSource.java
// flash
//
// Created by Niko Matsakis on Wed Dec 25 2002.
//

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

public class ListSource {
protected String[] mData;

public ListSource (String[] data) {
mData = data;
}

public int numberOfRowsInTableView (NSTableView view) {
return mData.length;
}

public Object tableViewObjectValueForLocation(NSTableView v, NSTableColumn c, int idx) {
return mData[idx];
}
}


niko
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Java Cocoa Table View DataSources (From: Niko Matsakis <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.