Passing SDataGridCoord in a variable not working in ShinobiDataGrid


#1

I had a grid using ShinobiGrid, but now I changed it to a ShinobiDataGrid and before I was able to create this variable:

SDataGridCoord const *clickedGridCoord;

and populate it here:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid willSelectCellAtCoordinate:(const SDataGridCoord *)gridCoordinate
{
if ((gridCoordinate.column.displayIndex==5||gridCoordinate.column.displayIndex == 6 || gridCoordinate.column.displayIndex == 7 ) && dataSource.dataForDatabase)
{
clickedGridCoord = gridCoordinate;
[self CreateCellDateModPopup:clickedGridCoord];
}
}

but when I call it again here…it crashes Thread 1:EXC_BAD_ACCESS (code = 1, address=0xc000000c)

- (void)ChangeCellWithStringDate :(NSString *)stringDate
{
CellData *cell = [dataSource.cellHolder objectAtIndex:clickedGridCoord.row.rowIndex];
//if sched start changed just change the date
if(clickedGridCoord.column.displayIndex == 5)
{
[[cell scheduledDate]setString:[NSString stringWithFormat:@"%@ 8:00:00 AM",stringDate]];
[dataSource SetUpScheduleTemplate:templateSelection];
[dataSource RecalculateScheduleDownIndex:clickedGridCoord.row.rowIndex];
}
//if actual start changed just change the date
else if(clickedGridCoord.column.displayIndex == 6)
[[cell actualDate]setString:[NSString stringWithFormat:@"%@ 8:00:00 AM",stringDate]];
//if actual finish changed and actual start empty fill both
else if(clickedGridCoord.column.displayIndex == 7 && [[cell actualDate] isEqualToString:@""])
{
[[cell actualDate]setString:[NSString stringWithFormat:@"%@ 8:00:00 AM",stringDate]];
[[cell finishedDate]setString:[NSString stringWithFormat:@"%@ 4:00:00 PM",stringDate]];
[cell setSelected:YES];
}
//if actual finish changed and actual start filled just change finished date
else if(clickedGridCoord.column.displayIndex == 7 && !([[cell actualDate] isEqualToString:@""]))
{
[[cell finishedDate]setString:[NSString stringWithFormat:@"%@ 4:00:00 PM",stringDate]];
[cell setSelected:YES];
}
[dataSource UpdateEdittedCells:cell];
[dataSource SetDisplayHolder];
//refresh table view
[spreadSheet reload];


}

when I was using ShinobiGrid, it was like this:

const SGridCoord *clickedGridCoord;

then populating here:

- (void)shinobiGrid:(ShinobiGrid *)grid willSelectCellAtCoord:(const SGridCoord *)gridCoord
{

//if actual start or actual finish.
if ((gridCoord.column==5||gridCoord.column == 6 || gridCoord.column == 7 ) && dataSource.dataForDatabase)
{
clickedGridCoord = gridCoord;
[self CreateCellDateModPopup:gridCoord];
}




}

and then calling it here:

- (void)ChangeCellWithStringDate :(NSString *)stringDate
{
CellData *cell = [dataSource.cellHolder objectAtIndex:clickedGridCoord.rowIndex-1];
//if sched start changed just change the date
if(clickedGridCoord.column == 5)
{
[[cell scheduledDate]setString:[NSString stringWithFormat:@"%@ 8:00:00 AM",stringDate]];
[dataSource SetUpScheduleTemplate:templateSelection];
[dataSource RecalculateScheduleDownIndex:clickedGridCoord.rowIndex-1];
}
//if actual start changed just change the date
else if(clickedGridCoord.column == 6)
[[cell actualDate]setString:[NSString stringWithFormat:@"%@ 8:00:00 AM",stringDate]];
//if actual finish changed and actual start empty fill both
else if(clickedGridCoord.column == 7 && [[cell actualDate] isEqualToString:@""])
{
[[cell actualDate]setString:[NSString stringWithFormat:@"%@ 8:00:00 AM",stringDate]];
[[cell finishedDate]setString:[NSString stringWithFormat:@"%@ 4:00:00 PM",stringDate]];
[cell setSelected:YES];
}
//if actual finish changed and actual start filled just change finished date
else if(clickedGridCoord.column == 7 && !([[cell actualDate] isEqualToString:@""]))
{
[[cell finishedDate]setString:[NSString stringWithFormat:@"%@ 4:00:00 PM",stringDate]];
[cell setSelected:YES];
}
[dataSource UpdateEdittedCells:cell];
[dataSource SetDisplayHolder];
//refresh table view
[spreadSheet reload];


}

and that worked…how come it does not work with ShinobiDataGrids?


#2

Greetings Program!

Don’t make clickedGridCoord a const and in willSelectCellAtCoordinate, set it like this:

clickedGridCoord = [[SDataGridCoord alloc] initWithCol:gridCoordinate.column row:gridCoordinate.row];

The only differences in the two code snippits I see (other than the addition of the column.displayIndex property) are:

// SGrid
CellData *cell = [dataSource.cellHolder objectAtIndex:clickedGridCoord.rowIndex-1];
[dataSource RecalculateScheduleDownIndex:clickedGridCoord.rowIndex-1];

// SDataGrid
CellData *cell = [dataSource.cellHolder objectAtIndex:clickedGridCoord.row.rowIndex];
[dataSource RecalculateScheduleDownIndex:clickedGridCoord.row.rowIndex];

Are you accessing the correct rowIndex? I’m assuming you’ve only got one section in your grid.

Wg