[英]NSInternalInconsistencyException with UITableViewController and a Storyboard-Pop
我將GrabKit集成到我的iPhone-App中,該應用程序是一個從社交網絡獲取照片的庫。 現在我有以下情況/問題:
我有一個UITableViewController-AlbumListViewController。 然后是一個UITableViewCell-AlbumCellViewController。 當您點擊其中一個單元(帶有照片的相冊)時,會有一個UITableViewController-PhotoListViewController和一個UITableViewCell-PhotoCellViewController。
此處的所有內容都可以找到,我可以瀏覽相冊,選擇其中一個,瀏覽其中的照片,然后當我選擇其中一張照片時,我的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
我的兩個UITableViewControllers的DataSource和Delegate都設置為File的Owner。
當我調試代碼時,找不到任何特殊的東西,可以加載所有照片,所有數組都充滿數據,沒有什么奇怪的。
只要按下NavigationController上的后退按鈕,就會調用以下兩個PhotoListViewController函數:
(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-Method的代碼:如果我對其進行調試,則第一次res等於0,第二次調用該方法時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;
}
我是GrabKit的開發人員。 感謝您使用它:)
實際上,GrabKit中的控制器僅用於演示目的,它們並不是設計為按原樣在項目中使用,更具體地說:GRKDemoPhotosList控制器並未在控制器層次結構中引入其他控制器。
因此,您所需要做的只是一點點修復,以使grabKit演示的控制器適合您的項目:)
我猜問題出在下面:
在[GRKDemoPhotosList viewWillAppear]中的_中,調用方法fillAlbumWithMorePhotos。
_當您從控制器彈出回到GRKDemoPhotosList時,此方法又被調用一次,並且會生成此錯誤。
嘗試在viewWillAppear方法中添加一個標志,以避免兩次調用fillAlbumWithMorePhotos,我想它會很好地工作。
如果您需要更多信息或幫助,請隨時通過郵件(gmail.com上的pierre.olivier.simonard)或通過Twitter(@pierrotsmnrd)與我聯系。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.