Vertical scroll Shinobi Grid is Crashing


#1

Hi folks!

We have a situation here, when I have too much data, and I need to scroll down my grid, it crash. Here is my shinobiGrid:cellForGridCoord method.

Also we make some classes, that inherit from ShinobiGrid and implemented delegate/datasource inside of it, so I only pass in the constructor a “Dataset” Class.

- (SGridCell *)shinobiGrid:(ShinobiGrid *)grid cellForGridCoord:(const SGridCoord *) gridCoord
{
    SGridCell *c;
    
    if([gridCoord hasRow:SGridRowZero])
    {
        SGridCell *cell;
        cell = [grid dequeueReusableCellWithIdentifier:kReuseIdentifierHeader];
        
        if(!cell)
            cell = [[SGridAutoCell alloc] initWithReuseIdentifier:kReuseIdentifierHeader];
        
        for (UIView *view in cell.subviews)
        {
            if ([view isKindOfClass:[UITextField class]] == NO) {
                [view removeFromSuperview];
            }
        }
        
        UILabel *headerLabel = [[UILabel alloc] initWithFrame:cell.bounds];
        headerLabel.backgroundColor = [_del HeaderBackgroundColor];
        headerLabel.textColor = [_del HeaderTextColor];
        headerLabel.textAlignment = UITextAlignmentCenter;
        
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            headerLabel.font = [UIFont fontWithName:@"Arial" size:14.f];
        headerLabel.text = [[_items keyValues] objectAtIndex:gridCoord.column];
        cell.backgroundColor = [_del HeaderBackgroundColor];
        [cell addSubview:headerLabel];
        c = cell;
    }
    else if(gridCoord.row.index <= [_items.items count])
    {
        SGridTextCell *cell = [grid dequeueReusableCellWithIdentifier:kReuseIdentifierRow];
        
        if(!cell)
            cell = [[SGridTextCell alloc]initWithReuseIdentifier:kReuseIdentifierRow];
        
        NSString *key = [[_items keys] objectAtIndex:gridCoord.column];
        
        NSDictionary *dict = [_items.items objectAtIndex:gridCoord.row.index - 1];
        cell.textField.font = [UIFont fontWithName:@"Arial" size:12.f];
        id text = dict[key];
        if([text isKindOfClass:[NSString class]])
        {
            if([text isEqualToString:@"0"]){
                cell.textField.textAlignment = NSTextAlignmentCenter;
            }
            //Cambio por: Cintia Cornu
            //Descripción: para centrar variacion%
            NSRange range = [text rangeOfString:@"%"];
            if (range.location != NSNotFound) {
                cell.textField.textAlignment = NSTextAlignmentCenter;
            }
            cell.textField.text = text;
        }
        else
        {
            // Los Nan
            cell.textField.textAlignment = NSTextAlignmentCenter;
            if([[text stringValue] isEqualToString:@"nan"])
                cell.textField.text = @"0";
            else
                cell.textField.text = [NSString stringWithFormat:@"%@", text];
        }
        
        NSRange range = [[NSString stringWithFormat:@"%@", text] rangeOfString:@"%"];
        
        if(range.location != NSNotFound)
            cell.textField.textAlignment = NSTextAlignmentCenter;
        
        UIColor *textColor = [_del FontColorForData:dict[key] InCord:gridCoord];
        if(textColor)
            cell.textField.textColor = textColor;
        cell.backgroundColor = [_del RowsBackgroundColor];
        
        c = cell;
    }
    else
    {
        if(_HasFooterCellsVisible)
        {
            
            SGridCell *cell;
            cell = [grid dequeueReusableCellWithIdentifier:kReuseIdentifierFooter];
            
            if(!cell)
                cell = [[SGridAutoCell alloc] initWithReuseIdentifier:kReuseIdentifierFooter];
            
            for (UIView *view in cell.subviews)
            {
                if ([view isKindOfClass:[UITextField class]] == NO) {
                    [view removeFromSuperview];
                }
            }
            
            NSString *key = [[_items keys] objectAtIndex:gridCoord.column];
            UILabel *footerLabel = [[UILabel alloc]initWithFrame:cell.bounds];
            footerLabel.backgroundColor = [_del FooterBackgroundColor];
            footerLabel.textColor = [_del FooterTextColor];
            
            if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                footerLabel.font = [UIFont fontWithName:@"Arial" size:14.f];
            cell.backgroundColor = [_del FooterBackgroundColor];
            
            NSString *text;
            
            if(gridCoord.column == 0)
                text = @"TOTAL:";
            else
            {
                text = [_items.items GetSumForKey:key];
                footerLabel.textAlignment = NSTextAlignmentCenter;
            }
            
            footerLabel.text = text;
            [cell addSubview:footerLabel];
            c = cell;
        }
    }
    
    return c;
}

#2

Sorry to hear that you are having problems with the grid! Could you let us know a few more details about the crash? What exception do you see when your app crashes? Do you see any messages in your console when the app crashes? How much data do you have in your grid?