0

I am trying to create a very simple Window for display a list of items that comes from an Sqlite3 database. I have a generic list of my objects, and I want to bind that to the controls on the windows. What is the best way to do this?

If it was .NET windows forms, I would do this, what is the Cocco equivalent? myBindingSource.DataSource = new List<MyObject>();

My ViewController.cs code currently looks like this:

List<MyObject> dataSource = DataStore.GetLibraries(); public override AwakeFromNib() { base.AwakeFromNib(); dataSource = GetMyObjects(); myArrayController.Bind("contentArray", this, "dataSource", null); // Throws error }

But this throws an error: this class is not key value coding-compliant for the key DataSource.

Thanks!

Humphrey
  • 4,108
  • 2
  • 28
  • 27

1 Answers1

0

After linking libsqlite3.dylib to your framework (General:Linked Frameworks and Libraries) and adding the database-file to your project you create an sqlite accessor class, to do the database connections and enable the queries.

If your project should also save into the database, on installation the database must be placed at a position where you have also write-access, this would be in the "Documents"-folder for an iphone app or in "Application Support" on MacOS X, but not in the application bundle itself. (Take care not to mess the owner-name, otherwise only root or you have write access and your customers won't)

To connect your query result to the Array-Controller which seems to be the heart of your question, the query's output needs to be formatted according to apple's KVC rules. This is done by creating an NSDictionary (with objects and keys) and set up the array controller to read in from this dictionary.

The link from where i got this to work in my own projects has unfortunately been deleted, but i found you two tutorials, that give you the necessary function-calls, if you feel you need more details on this: a) for the sqlite connection: http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_4_iPhone_Application_(Xcode_4) b) for connecting an NSArrayController with a Dictionary: http://ihoneylocust.wordpress.com/2013/02/19/first-mac/

kilian
  • 29
  • 4