Bind NSSlider with NSTableView - objective-c

Data:
An entity with an attribute 'page' (int).
Interface:
NSSlider- value is bound to NotesController.selection.page
NSTableView- value of column 1 is bound to NotesController.arrangedObjects.page
I want to be able to interact with either component and have the change be reflected in both. Above setup works perfectly when I switch between rows in tableview (the slider goes to the corresponding value). However when I play around with slider it changes the value of the selected row instead of changing the index of selected row. This is obviously easily fixable with target/action but is there any workaround that only uses bindings? Thanks.

You need to bind your slider's value to NotesController.selectionIndex.

Related

Using placeholder template in core data without saving the placeholders?

I am wondering if its possible to have a core data and use a NSFetchedResultsController to display template holders; without saving the placeholder template holder to core data.
I am writing an app where a table view will have the following characteristics
Maximum amount of rows (ie: 8)
Each cell uses a partial view, a single table cell instance with clickable buttons;
A user clicking on the buttons replaces the content for each button
When a user comes to save the data it stores the content in the exact places, but crucially it should not save the blank placeholder state; but still respect the placement positioning.
IE: Lets say a user picks the right button for cell 1 and saves it;
when the the user returns to this dataset sometime in the future, it
should have the imagery and data in the correct place; but still keep
the left button for cell 1 empty (placeholder)
The reason I don't want to save the placeholder content is because I consider this data to be "dirty"; its meaningless and has no place in a dataset; its a view; not data.
Currently:
I create data using insertInManagedObjectContext but do not save it until the user has pressed save.
Each matchRow has many fighters. This relationship is a NSOrderedSet, managed by core data.
The problems I'm having are;
NSFetchedResultsController only respects saved core data items; and ignores the placeholder data.
If a user only saves one (right button) data, the NSOrderedSet sees this as the first (left button) data; which is in correct
If I strip out all the placeholder structures from the core data in a pre-save action, the effect is that the order the user wanted is now lost and it causes a crash when reloading because the size of the arrays are incorrect.
Currently the only way around this is to stop using
NSFetchedResultsController and use a NSArray; and put the placeholders into the array too, then save everything, (dirty objects) and all.
I really don't want to do that. The placeholder content isn't meant to be saved.
I've been reading a blog post on using separate classes for special cases where he has different data sources; and uses the technique to separate class for the "empty" case, and to set it as the table view’s datasource when it's empty.
Whilst this is interesting, it only solves it for an empty case; when my requirement is that the partial view should handle all states; empty data and partial data.
One idea I have is that we need another entity between our record and our match rows;
Match - MatchRowMeta - Fighter
Not sure what the relationship would be
where;
RowMeta {
record.obj (relationship)
fighters.obj (relationship)
positionID (integer) - which button has been set
}
But I don't think this is the best way to do it; it seems expensive and a lot of heavy lifting to do something relatively simple.
Thus, my question:
Is it possible to have a table view made up of template holders; where the structure is saved to core data but none of the empty (dirty) objects are saved; plus NSFetchedResultsController will respect the structure; even when its empty or partially empty?
Edit: Added entity diagram

How to specify different editor widgets for the same column in Dojo DataGrid

I am wondering, is there an official way to specify a different widget editor for the same column in a DataGrid (different rows)?
I found dojox.grid.cells._MultipleEditor, but it is quite complicated and not officially supported.
This is for creating things like a property sheet with DataGrid.
EDIT: People seem to suggest using dgrid. However, I am not sure if dgrid has this feature. Also, unfortunately, ... drum roll... horror music... I must support IE6.
Well, there seems to be a way to do it. Doesn't seem to show much negative side effects (so far)...
Create one column for each value type, one after the other.
Tag each column with a CSS class to indicate its value type (via classes). For example: classes="multivalue int"
For each column, tag it with the correct editor widget and the appropriate constraint & options.
Put styles on each row (with onStyleRow) that correspond to each type. For example, add a type-int class to the row that has an int type.
Put in a CSS style that initially hides all the multi-valued cells:
.dojoxGridCell.multivalue { display:none; }
Un-hide all the cells with the correct type:
.dojoxGridRow.type-int .dojoxGridCell.multivalue.int
{
display:table-cell;
*display:block; /* For IE6/7 */
}
For this to work, obviously, each row must match exactly one column.
Obviously, you must set all these fields to the same property name. DataGrid allows you to do that.
Put display:none (via CSS etc.) on all the header cells of multi-valued columns except the first one. Otherwise, you'll end up with too many header cells.

How to use a single NSValueTransformer subclass to toggle the titles of multiple menu items

I would like to make some bindings that toggle item titles in a popup menu based on a single numerical value in a text field. Let me explain:
This is my UI:
I want my menu items to automatically adjust to singular or plural based on the number in the text field. For example, when I type "1" in the box, I want the menu items to be labeled "minute", "hour" and "day". When I type "4", I want the menu items to be labeled "minutes", "hours" and "days".
What I did to date:
I bound the three menu item's labels to the same key path as the text field's value.
I created an NSValueTransformer subclass to interpret the value in the text field and return singular or plural to be used as item titles.
I applied this value transformer to the three bindings.
The issue:
My value transformer can either return singular or plural but it can't set the appropriate string based on the menu item it's applied to.
It looks to me like a value transformer is generic and can't return different values for different destinations. That would mean that to have the three titles change automatically, I would need to have three different value transformers that return the appropriate string for each menu item. That doesn't seem optimal at all.
Ideally I would be able to combine a string stored in the destination menu item (let's say in the item's tag property) with an "s" in the value transformer when the text field's value is larger than one, or something similar that would enable me to use a single value transformer for all the menu items.
Is there something I missed? What would be an ideal solution?
Okay, this is probably not an ideal solution, but something you could consider: if you set your value transformers from your code (and not in IB), you could instantiate 3 different transformers of the same class. You could give your value transformer an ivar NSString *unit (and add something like [[MyValueTransformer alloc] initWithUnit:]) to allow each to return their own string, but you still have to write the value transformer's code only once.
(Also, if you're ever going to consider making your application localizable, simply appending an "s" to create the plurals is not going to work. You could of course add ivars for both NSString *singular and NSString *plural to do that.)
Edit: Wait, I just realized you can register value transformers! If you register them as MyValueTransformerHours and MyValueTransformerMinutes (by manually allocating and initializing them in your code), you can use them from Interface Builder. See also https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ValueTransformers/Concepts/Registration.html#//apple_ref/doc/uid/20002166-BAJEAIEE.

Show more than one Object in a NSTableView row

I'm new here at stackoverflow :) But I think, this is the right place to ask my question.
I'm a new developer with Cocoa and Objective-c & I'm trying to write my first App for Mac: a ToDo App.
At this moment, i can save ToDo's and delete them, but now, I want to add some features like CreationDate, some Tags (in mutablearray), and if the ToDo is finished or not. Im not working with an ArrayController, I'm saving the encoded NSMutableArray into a File (Library/Application Support/AppName) and reading it from there.
This all must be in one Row, because it is looking Like this:
Current appearance http://img683.imageshack.us/img683/7595/bild2ss.png
Where Title is, should be the Content of the ToDo, where the Blue Box is, should be the Status (Blue = undone, Grey = Done) and where Subtitle is should be the Date and the Tags (03.01.2009 - tag1, tag2, tag3)
I now how to addObjects into an mutablearray but, if i wanna save all this 4 informations into this array, i dont know how to make this.
I've got an Model, which is initializing with this 4 infomations, but how to save this? Must I save this for informations in one array and this array in my mutablearray?
The solution is actually the opposite: Have one object per row.
This is where your model layer (the M in MVC) comes in: The object for each row is a model object, an instance of a class you construct, and the icon, title, and subtitle are properties of that object.
Then, make a custom cell for your table column to display the model object in that way. The cell is part of the View layer—the V in MVC.
The C in MVC sits in between the Model and View: It's the object that owns the model and is the data source (whether by Bindings or not) of the table view. The table view gets the model objects from this object to feed them to the cell. This middle object is a Controller.
Now i have it!
I've only one Cell for the Content with an ArrayController.
I'm setting the other Informations with -(id)init for each row.
There are 3 Objects: content, status and date, and for each status i display another image (done, undone, ...).
Thank you very much for your Help! I'm trying to finish the Beta for everyone :)

How do you make a Text Label display how many rows there are in the table

I am using Core Data and want a Text Label to display how many rows there are in the table, what code would I need to enter in the class file's to do this?
Assuming your NSTableView's columns are bound to an NSArrayController, you can bind the value of the NSTextField label to your array controller's with controller key "arrangedObjects" and with a key path of #count. If you want to bind the text field to something like "x rows" where x is the number of rows, you would bind the "Display Pattern Value1" to the same (arrangedObjects.#count) and use "%{value1}# rows" as the Display Pattern.
Set up a fetch request on your managed object context like you normally would, and call countForFetchRequest:. Don't forget to subscribe to NSManagedObjectContextObjectsDidChangeNotification so you can update it when objects are added or removed!