ソーシャルネットワークから写真を取得するためのライブラリである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;
}