CollectionView Delegation (pt. 1) [CollectionRowDelegate]
Although this is not yet the post I promised, it is in the same vein. In this post I am going to try to explain using custom row heights in a list view.
To have rows in a list with different heights you need to do one of the following:
1.) Make your [array | collection]
controller implement SC.CollectionRowDelegate. 2.) Create an SC.Object that implements SC.CollectionRowDelegate.
The code for this would look like the following:
Myapp.SomeObject = SC.Object.create(
SC.CollectionRowDelegate, {
// abstract method implementation
});
The abstract method implementation mentioned above refers to the method that you need to override from the collection row delegate mixin you just included. The method name is “contentIndexRowHeight” and the params that it will receive are: view ( the current view), index ( the index of the list item), and content.
The purpose of the method is to return the custom row height of the current list item to the listview and then it gets sized properly.
You also must set a property named “customRowHeightIndexes” to an SC.IndexSet of the indexes in your list that you want to have custom heights.
The last thing you have to do to make this work is to set the delegate on the listview to this object.
One nice thing to note: if you modify the cutomRowHeightIndexes the list will be redrawn. For example, if you were to Remove an index from this properties indexset, that index would no longer have the custom height and would be rendered with the standard rowheight!
Hopefully this has given you a quick overview of what you can do with delegates in Sproutcore.
Over the weekend I plan to write the post I promised. But hopefully this will do in a quick pinch.
Until next time, happy hacking!!!