I have created a small application,in which i have draged and droped a NSTableView onto the window and binded to an datasource, in the datasource i have created NSMutableArray and added 2 records to it. And also defined methods numberOfRowsInTableView and rest of the methods.
When i run the application it is showing the rows but the data is not displaying.
So. You've connected your table view's datasource outlet to some controller object that adopts NSTableDataSource protocol.
You mention numberOfRowsInTableView, which tells the table how many rows it should expect but lump together the "rest of the methods." One of those other methods is exactly responsible for showing the data for a given row and column.
What seems to be happening is this:
Table: "How many rows we got here?"
Data Source: "Three."
Table: "Gimme the object to display at
row 0, column 0."
Data Source: [ sound of crickets
chirping ]
You should probably post the exact code you're using for your implementation of the tableView:objectValueForTableColumn:row: method. Remember to include the method signature itself, given its importance in being recognized as the selector the protocol is looking for.
Related
I've a strange question I tought about for exercise that is not easy to explicate.
Suppose I've a form with some TDBEdit object. Nturally every TDBEdit object reference a database field.
Here a simple example:
When the user click the save button (the little disk icon on the top of the image) I make the data validation and, if data are correct, I register them into the database. Simple!
But my mental exercise is this:
all my data tables are included in a datamodule so what about if I would like to trasfer the data validation from the form to the datamodule?
Simple... it's enough to validate the table fields like this:
if (fAut_Cognome.Value = '') or (fAut_Nome.Value = '') then begin
...
Give error messsage
...
end;
But If the user doesn't leave the last TDBEdit object the relative database field is not valorized (for example while adding a new record to the table the database field will ane no value).
So my question is this: there is a way to validate data, from datamodule, even if the user doesn't leave the TDBEdit control?
You should plug the OnBeforeExit event of your TDBEdit to a method in the Datamodule. But as said in comments you will only test the control's value, not the DB field's value because not updated yet.
I have a working system that lets me build a database containing instances of various entities , all linked together nicely.
Before I knew I would care, I came across a tutorial on using Core Data and bindings, and it went through a complete case where you get a table showing all the entities of some type with a column for each property. It showed both the UI side and the Data model side - not that I need the data model part at this point. Now, darned if I can find it. This is one of those things that is supposed to be easy, and requires virtually no code, but getting exactly the right connections in UIBuilder is not going to happen if I can't find instructions.
Also, I thought I came across an example of something like a query editor where the user could select which properties to sort on, which to match on, etc. Did I imagine that?
Anyone out there know where I can find such?
Sure, you can do this without code:
Add an array controller to your nib.
Bind or connect an outlet for its managed object context
Set the array controller to Entity mode, fill in the entity name, and select Prepares Content.
Bind your table view columns to array controller's arranged objects, and fill in the key name for the model key.
Regarding the query editor, open up the model, and on the Editor menu click Add Fetch Request.
I found at least a partial answer to the query editor question, in this apple tutorial. Not sure how far it will get me, as I prefer to write code where possible, since then I can leave a trail of comments.
I got a silly general question...
If I generate a strongly typed view of an entity and chose "edit" as scaffolding, then the view does contain every column for that table. Changing and saving the values via setting it modifierd and call db.SaveChanges() does work in the controller. So far, so good.
But if I remove just one of that columns inside the view, then saving doesn't work anymore.
Is there a rule describing this? Is it only possible to make view with every column when wanting to save the model later on? I don't want to make 90 of 100 columns "hidden"...
PS: When editing a value in another table which is connected via Foreign Key (like customer.address.STREET) saving also does not work. Does everything of the entity ADDRESS has to be inside the view? I really don't get that.
Besides that: If I create my own ViewModel containing two entities: Do they also have to hold every column of both entities? This would be a whole bunch of traffic...
Answer is: You should not use the .Modified state. Instead using the UpdateModel method works fine without every field.
I have a Cocoa Mac application with a search field and a collection view bound to an sqlite table through CoreData. The table contains several hundred thousand records with text fields (name, place, ...) indexed by name. I'm using BEGINSWITH predicate in a search field binding to select a dozen of records for display in a collection view. Everything works fine, but the problem is that CoreData loads the whole table into memory at the first query request and only then does the necessary filtering of records for display which means considerable delay for the user.
Is there a way to set up CoreData so that the whole table does not load into memory? Ideally, I would like to fetch only the first 100 items from a range of alphabetically sorted records for every query in the search field.
On iOS, this would be achieved using a NSFetchedResultsController. The following question describes the Mac equivalent controllers (such as NSArrayController): NSFetchedResultsController Mac OSX Cocoa equivalent.
EDIT
As per my comment below, a NSFetchRequest should be created in conjunction with the array controller. This can then be configured with fetchLimit and fetchOffset to determine how many fetch results are returned.
Make sure that you have the fetch request set to fetch as faults only. That way only the objects whose attributes who are actively accessed will be fully loaded into memory.
I have a simple question:
How to show serial nos. or (row no. +
1) in a table column using cocoa bindings and array controller?
I have made an application using cocoa bindings and array controller, in which I am displaying names of certain persons in a table column. The class from which I am displaying is named as: Person. Now I want to show serial nos. in first column, such that list gets displayed like this :
1 / John
2 / Peter
It is very easy to do if I use data source method:
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
I just need to return something like this :
return [NSString stringWithFormat:#"%d",rowIndex+1];
but I am not getting how to do this via cocoa binding and array controller.
Can anyone suggest me solution for it?
Thanks,
Miraaj
One way you can do this is to actually mix using bindings and a data source with the same table view. Go ahead and hook up bindings for the rest of your table columns, but leave the one you want to display the indices in unbound. Then, just implement the table data source as normal for just that one column. It should only ever ask you for data fir Amy unbound columns, and just use the bound data for the rest.