Question

I integrated GrabKit in my iPhone-App, which is a Library to Grab Photos from social Networks. Now I have the following situation/problem:

I have a UITableViewController - AlbumListViewController. Then there's a UITableViewCell - AlbumCellViewController. When you tap on one of these cells - albums with photos There's a UITableViewController - PhotoListViewController and a UITableViewCell - PhotoCellViewController.

Everything here works just finde, I can browse albums, choose one, browse the photos in it and then when I choose one of the single photos, there is a PushViewController to my SetPhotoViewController, which displays the selected image in Fullscreen.

Now when I want to use the back-Button of my navigation bar in the SetPhotoViewController, the crashes with the following message:

*** Assertion failure in -[UISectionRowData refreshWithSection:tableView:tableViewRowData:], /SourceCache/UIKit_Sim/UIKit-2372/UITableViewRowData.m:400
2012-10-22 22:49:32.814 Amis[1820:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to allocate data stores for 1073741821 rows in section 1. Consider using fewer rows'
*** First throw call stack:
(0x23de012 0x1b63e7e 0x23dde78 0x15f9f35 0xc8f83b 0xc923c4 0xb56fa2 0xb5692c 0x1690f 0x1cd653f 0x1ce8014 0x1cd87d5 0x2384af5 0x2383f44 0x2383e1b 0x2a9a7e3 0x2a9a668 0xaab65c 0x42fd 0x2b75)
libc++abi.dylib: terminate called throwing an exception

DataSource and Delegate of my two UITableViewControllers are both set to File's Owner.

When I debug trough the code, I can't find any special things, all photos can be loaded, all the arrays are filled with data, there's nothing strange.

Here are the two functions of the PhotoListViewController which get called, as soon as I press the back button on my NavigationController:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = nil;
    NSLog(@"%i", indexPath.row);
    NSLog(@"%ii", indexPath.section);
    // Extra Cell
    if ( indexPath.section > _lastLoadedPageIndex ){    

        static NSString *extraCellIdentifier = @"ExtraCell";

        cell = [tableView dequeueReusableCellWithIdentifier:extraCellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:extraCellIdentifier];
        }

        cell.textLabel.text = @"load more";
        cell.textLabel.font = [UIFont fontWithName:@"System" size:8];



    } else {

        static NSString *photoCellIdentifier = @"photoCell";

        cell = [tableView dequeueReusableCellWithIdentifier:photoCellIdentifier];
        if (cell == nil) {

            cell = [[[NSBundle mainBundle] loadNibNamed:@"PhotoRowViewController" owner:self options:nil] objectAtIndex:0];
        }


    }    

    // setting of the cell is done in method [tableView:willDisplayCell:forRowAtIndexPath:]

    return cell;
}

and..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // extra cell
    if ( [cell.reuseIdentifier isEqualToString:@"ExtraCell"] ){ 

        if ( state == GRKDemoPhotosListStateAllPhotosGrabbed ) {

            cell.textLabel.text = [NSString stringWithFormat:@" %d photos", [[_album photos] count] ];

        }else {
            cell.textLabel.text = [NSString stringWithFormat:@"Loading page %d", _lastLoadedPageIndex+1];
            [self fillAlbumWithMorePhotos];
        }


    } else  // Photo cell
    {
        NSArray * photosAtIndexPath = [self photosForCellAtIndexPath:indexPath];

       [(PhotoRowViewController*)cell setPhotos:photosAtIndexPath];


    }

}

What am I missing?

Edit: The code of the numberOfRowsInSection-Method: If I debug it, the first time res is equal 0, the second time the method gets called, res is equal 322121535.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.

    NSUInteger res = 0;

    if ( state == GRKDemoPhotosListStateAllPhotosGrabbed && section == _lastLoadedPageIndex ) {

        NSUInteger photosCount = [_album count];

        // Number of cells with kNumberOfPhotosPerCell photos 
        NSUInteger numberOfCompleteCell = (photosCount - section*kNumberOfRowsPerSection*kNumberOfPhotosPerCell) / kNumberOfPhotosPerCell;

        // The last cell can contain less than kNumberOfPhotosPerCell photos
        NSUInteger thereIsALastCellWithLessThenFourPhotos = (photosCount % kNumberOfPhotosPerCell)?1:0;

        // always add an extra cell
        res =  numberOfCompleteCell + thereIsALastCellWithLessThenFourPhotos  +1 ;


    } else if ( section > _lastLoadedPageIndex) {

        // extra cell
        res = 1;

    } else res = kNumberOfRowsPerSection;


    return res;

}
Was it helpful?

Solution

I'm the developer of GrabKit. Thanks for using it :)

Actually, the controllers in GrabKit are there for demonstration purpose only, they are not designed to be used "as is" in a project, and more specifically : The GRKDemoPhotosList controller was not made to have another controller pushed in the controllers hierarchy.

So what you need is just a little fix to make grabKit demo's controllers fit to your project :)

I guess the problem is the following :

_ in [GRKDemoPhotosList viewWillAppear], the method fillAlbumWithMorePhotos is called.

_ when you pop back from your controller to GRKDemoPhotosList, this method is called one more time, and it generates this bug.

Try to add a flag in the viewWillAppear method, to avoid calling fillAlbumWithMorePhotos twice, I guess it'll work fine.

Feel free to contact me by mail ( pierre.olivier.simonard at gmail.com ) or on twitter ( @pierrotsmnrd ) if you need more informations or help :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top