Coredata endupdates crash + viewForHeaderInSection issue
<p>I come across very unusual issue. I have implemented coredata with fetchviewcontroller. when I delete the the particular row of last section I got the error.</p>

<p>CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil with userInfo (null)</p>

<p>And then my table get totally disturbed and all row got messy..Please have look at screenshots.
After long debugging I found that magic happened in <strong>viewForHeaderInSection</strong>. If I assign text to label then this issue occure , if i dont then it work and never get any issue. Please refer the code below.</p>

<pre><code> - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {

        NSString *programId = [[[_fetchedResultsController sections] objectAtIndex:section] name];

        ImageQueue *info = [_fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];


        UIView  *baseView = [[UIView alloc] init];
        baseView.backgroundColor = [UIColor appOrangeColor];

        UILabel *lblProgramTitle = [[UILabel alloc] init];
        lblProgramTitle.frame = CGRectMake(0, 0, 0, 0);
        lblProgramTitle.numberOfLines = 0;
        lblProgramTitle.lineBreakMode = NSLineBreakByWordWrapping;
        lblProgramTitle.backgroundColor = [UIColor clearColor];
        lblProgramTitle.textColor = [UIColor blackColor];
        lblProgramTitle.font = [UIFont fontWithName:FONT_OPENSAN_SEMIBOLD size:16];
//This line when commented work otherwise issue occure.
        lblProgramTitle.text = [NSString stringWithFormat:@"%@\n( %@ )",info.eventName,info.programName];
        lblProgramTitle.tag = 100;
        [baseView addSubview:lblProgramTitle];

        NSLog(@"%@\n( %@ )",info.eventName,info.programName);

        [lblProgramTitle enableAutolayout];
        [lblProgramTitle leadingMargin:5];
        [lblProgramTitle trailingMargin:100];
        [lblProgramTitle topMargin:15];
        [lblProgramTitle bottomMargin:15];


        UIButton *btnUploadAll = [UIButton buttonWithType:UIButtonTypeSystem];
        btnUploadAll.backgroundColor = [UIColor clearColor];
        btnUploadAll.frame = CGRectMake(0, 0, 0, 0);

        [btnUploadAll setTitle:@"Upload All" forState:UIControlStateNormal];
        [btnUploadAll setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btnUploadAll.titleLabel.font = [UIFont fontWithName:FONT_OPENSAN_SEMIBOLD size:16];
        [btnUploadAll addTarget:self action:@selector(uploadAll:) forControlEvents:UIControlEventTouchUpInside];
        [baseView addSubview:btnUploadAll];

        btnUploadAll.tag = [programId integerValue];

        [btnUploadAll enableAutolayout];
        [btnUploadAll fixWidth:80];
        [btnUploadAll fixHeight:50];

        [btnUploadAll trailingMargin:5];
        [btnUploadAll centerY];

        return baseView;

    }
</code></pre>

<p>The error mentioned above occurs when the endupdate is executed</p>

<pre><code>- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    // The fetch controller has sent all current change notifications, so tell the table view to process all updates.
    [tableCart endUpdates];
}
</code></pre>

<p><a href="https://i.stack.imgur.com/AKvG6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AKvG6.png" alt="Image 1 "></a></p>

<p><a href="https://i.stack.imgur.com/PDd6k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PDd6k.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/HhwUC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HhwUC.png" alt="enter image description here"></a></p>