0

ソーシャルネットワークから写真を取得するためのライブラリであるiPhone-AppにGrabKitを統合しました。今、私は次の状況/問題を抱えています:

UITableViewController-AlbumListViewControllerがあります。次に、UITableViewCell-AlbumCellViewControllerがあります。これらのセルの1つ(写真付きのアルバム)をタップすると、UITableViewController(PhotoListViewController)とUITableViewCell(PhotoCellViewController)があります。

ここですべてが機能します。アルバムを参照し、1つを選択し、その中の写真を参照します。次に、単一の写真の1つを選択すると、SetPhotoViewControllerにPushViewControllerがあり、選択した画像がフルスクリーンで表示されます。

SetPhotoViewControllerでナビゲーションバーの戻るボタンを使用すると、次のメッセージが表示されてクラッシュします。

*** 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

2つのUITableViewControllerのDataSourceとDelegateは両方ともFile'sOwnerに設定されています。

コードを介してデバッグすると、特別なものは見つかりません。すべての写真を読み込むことができ、すべての配列にデータが入力されます。何も奇妙なことはありません。

NavigationControllerの戻るボタンを押すとすぐに呼び出されるPhotoListViewControllerの2つの関数は次のとおりです。

(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;
}

と..

- (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];


    }

}

私は何が欠けていますか?

編集:numberOfRowsInSectionのコード-メソッド:デバッグすると、最初のresは0に等しく、2回目にメソッドが呼び出されると、resは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;

}
4

1 に答える 1

5

私はGrabKitの開発者です。それを使用していただきありがとうございます:)

実際、GrabKitのコントローラーはデモンストレーション目的でのみ存在し、プロジェクトで「そのまま」使用するようには設計されていません。具体的には、GRKDemoPhotosListコントローラーは、コントローラー階層に別のコントローラーをプッシュするようには作成されていません。

したがって、必要なのは、grabKitデモのコントローラーをプロジェクトに適合させるためのほんの少しの修正です:)

問題は次のとおりだと思います:

_ [GRKDemoPhotosList viewWillAppear]で、メソッドfillAlbumWithMorePhotosが呼び出されます。

_コントローラーからGRKDemoPhotosListに戻ると、このメソッドがもう一度呼び出され、このバグが発生します。

viewWillAppearメソッドにフラグを追加して、fillAlbumWithMorePhotosを2回呼び出さないようにしてください。これで、問題なく動作すると思います。

さらに詳しい情報やヘルプが必要な場合は、メール(gmail.comのpierre.olivier.simonard)またはツイッター(@pierrotsmnrd)でお気軽にご連絡ください:)

于 2012-10-23T11:06:47.000 に答える