I am trying to have the selection color, based on row, be different. Defining a color in the selection theme will change all of my rows when selected to the same color. I would like my rows to be a different color based on row. Specifically, I am trying to make it look like the rows are not being selected at all. Because I am using the data source helper, and alternating colors(white & blue), the only alternative I have found to make the rows still selectable, and not appear as though they are changing colors, is to use the willDisplayCell method which I have displayed below:
-(void)gridView:(IGGridView*)gridView willDisplayCell:(IGGridViewCell*)cell forPath:(IGCellPath*)path{
//overwrite selected color, makes row colors not change when selected
NSColor *cellColor= cell.backgroundColor
cell.selectedColor = cellColor;
}
However, if my rows exceed beyond the views scrollview, and I scroll down, the cells IGCellPath will be reset to the new viewable cell, which causes my selected colors to be skewed. IE. if my fifth row is not viewable, but then I scroll to have it be the first row from the top of my gridView, it's new rowPath is now 1, instead of 5. I will then notice that if I select a white row, it will sometimes be blue, and vice versa. I assume this caused by dequeResuableCell, which is a function I will still need to implement.
I am not sure if I have missed alternative methods/properties, or could implement willDisplayCell in a better fashion. Is there any other way to have my rows with alternating colors still be selectable, but retain the current background color for each row?
You make a very good point. After quite a bit of refactoring, I am no longer updating the entire grid when I want to refresh that one fixed cell, but instead am resetting the fixed column cell at my selected row as you suggested. Now I no longer have the issue of the changing cell path when scrolling, so I can set my row color appropriately.
Thanks for all your help!
Hi Brett,
Hmm, that shouldn't cause the row paths to change. By calling updateData, wilDisplayCell will fire again and you should be ok. Although if i had to guess, perhaps its b/c the cell is already selected, setting the selectedColor doesn't invalidate the cell's backgroundColor if it's already selected.
Anyways, I wouldn't update the data on the grid, everytime a cell is selected. If you want to update your custom fixedCell when it's selected, i would instead just get a handle on that cell and call a public method on it that triggers an update.
For example:
-(void)gridView:(IGGridView *)gridView didSelectRowAtPath:(IGRowPath *)path
{
IGCellPath* fixedCellPath = [IGCellPath pathForRow:path.rowIndex inSection:path.sectionIndex inColumn:0 isFixed:IGGridViewFixedColumnDirectionLeft];
YourCustomCell* cell = [gridView cellAtPath:fixedCellPath];
[cell toggelView];
In the code above, you would change the column index to the index of your FixedLeft Column. Then you'd asked the grid for your cell using that path. If the cell is in view, the cell returned won't be nil, and you'll be able to call your own custom method to update it's display.
Does that sound like it will work for you?
-SteveZ
Sorry for the confusion, it looks like the reason why my cells path is changing is because I am updating the grid by calling updateData in the method:
-(void)gridView:(IGGridView *)_gridView didSelectRowAtPath:(IGRowPath *)path{
Unfortunately, I need to upgrade the grid to call the fixed left cell method:
- (void)gridView:(IGGridView *)_gridView willDisplayFixedLeftCell:(IGGridViewCell *)cell forPath:(IGCellPath *)path{
In this method, I am expanding or contracting a view in a custom cell, to make it look like a tab is coming out of the row. The only way I have found to make that fixed cell's view update is to call the updateData method which will then create a call for willDisplayFixedCell. Is there any work around to keep my cell path consistent, but also be able to update my views in my custom fixed cell?
I have to apologize, i don't think i'm completely following.
Why is your cell's path changing?
As you scroll, are you removing data from your dataSource and updating the grid?
And to answer your question regarding the Data Source, I am using the IGGridViewDataSourceHelper