‘InvalID update: invalID number of rows in section 0. The number of
rows contained in an existing section after the update (5) must be
equal to the number of rows contained in that section before the
update (5),plus or minus the number of rows inserted or deleted from
that section (0 inserted,1 deleted) and plus or minus the number of
rows moved into or out of that section (0 moved in,0 moved out).’
以下是详细信息:
我打开单元格时使用代码打开钢琴表它给了子单元格每行有不同数量的单元格它工作得很好但我需要修改一些东西,当我点击它打开的行然后如果我点击另一行我需要它打开第二个并关闭第一个打开的行
这是我的代码
rootVIEw.m
#pragma -mark tableVIEwDelegate- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw { return 5;}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { GCRetractableSectionController* sectionController = [self.retractableControllers objectAtIndex:section]; // NSLog(@"sectionController.numberOfRow %d",sectionController.numberOfRow ); return sectionController.numberOfRow;}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { GCRetractableSectionController* sectionController = [self.retractableControllers objectAtIndex:indexPath.section]; return [sectionController cellForRow:indexPath.row];}- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"index path section %d indexrow %d",indexPath.section,indexPath.row); GCRetractableSectionController* sectionController = [self.retractableControllers objectAtIndex:indexPath.section]; // vc.open = !vc.open;// return [sectionController dIDSelectCellAtRow:indexPath.row]; if (indexPath.row == 1) { [myCustomVIEw setHIDden:YES]; NSLog(@"index path 11111 111111 1111111 indexrow %d",indexPath.row); } else if (indexPath.row == 2) { } return [sectionController dIDSelectCellAtRow:indexPath.row];}
// GCRetractableSectionController.m
#import "GCRetractableSectionController.h"#import "RootVIEwController.h"@interface GCRetractableSectionController ()@property (nonatomic,assign) UIVIEwController *vIEwController;- (voID) setAccessoryVIEwOnCell:(UItableVIEwCell*) cell;@end@implementation GCRetractableSectionController@synthesize uSEOnlyWhiteImages,TitleTextcolor,TitleAlternativeTextcolor;@synthesize vIEwController;@synthesize open,rowAnimation;@synthesize backUp;#pragma mark -#pragma mark Initialisation- (ID) initWithVIEwController:(UIVIEwController*) givenVIEwController { if ((self = [super init])) { if (![givenVIEwController respondsToSelector:@selector(tableVIEw)]) { //The vIEw controller MUST have a tableVIEw proprety [NSException raise:@"Wrong vIEw controller" format:@"The passed vIEw controller to GCRetractableSectionController must respond to the tableVIEw proprety"]; } self.vIEwController = givenVIEwController; // self.open = NO; self.uSEOnlyWhiteImages = NO; self.rowAnimation = UItableVIEwRowAnimationtop; } return self;}#pragma mark -#pragma mark Getters- (UItableVIEw*) tableVIEw { return [self.vIEwController performSelector:@selector(tableVIEw)];}- (NSUInteger) numberOfRow { NSLog(@"the count %d",self.contentNumberOfRow); return (self.open) ? self.contentNumberOfRow + 1 : 1;}- (NSUInteger) contentNumberOfRow { return 0;}- (Nsstring*) Title { return NSLocalizedString(@"No Title",);}- (Nsstring*) TitleContentForRow:(NSUInteger) row { return NSLocalizedString(@"No Title",);}#pragma mark -#pragma mark Cells- (UItableVIEwCell *) cellForRow:(NSUInteger)row { UItableVIEwCell* cell = nil; if (row == 0) cell = [self TitleCell]; else cell = [self contentCellForRow:row - 1]; return cell;}- (UItableVIEwCell *) TitleCell { Nsstring* TitleCellIDentifIEr = [NsstringFromClass([self class]) stringByAppendingString:@"Title"]; UItableVIEwCell *cell = [self.tableVIEw dequeueReusableCellWithIDentifIEr:TitleCellIDentifIEr]; if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleValue1 reuseIDentifIEr:TitleCellIDentifIEr]; } cell.textLabel.text = self.Title; if (self.contentNumberOfRow != 0) { cell.detailTextLabel.text = [Nsstring stringWithFormat:NSLocalizedString(@"%i items",),self.contentNumberOfRow]; cell.selectionStyle = UItableVIEwCellSelectionStyleBlue; [self setAccessoryVIEwOnCell:cell]; } else { cell.detailTextLabel.text = NSLocalizedString(@"No item",); cell.selectionStyle = UItableVIEwCellSelectionStyleNone; cell.accessoryVIEw = nil; cell.textLabel.textcolor = [UIcolor blackcolor]; } return cell;}- (UItableVIEwCell *) contentCellForRow:(NSUInteger)row { Nsstring* contentCellIDentifIEr = [NsstringFromClass([self class]) stringByAppendingString:@"content"]; UItableVIEwCell *cell = [self.tableVIEw dequeueReusableCellWithIDentifIEr:contentCellIDentifIEr]; if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleValue1 reuseIDentifIEr:contentCellIDentifIEr] ; cell.accessoryType = UItableVIEwCellAccessorydisclosureIndicator; } cell.textLabel.text = [self TitleContentForRow:row]; return cell;}- (voID) setAccessoryVIEwOnCell:(UItableVIEwCell*) cell { Nsstring* path = nil; if (self.open) { path = @"UpAccessory"; if (self.TitleAlternativeTextcolor == nil) cell.textLabel.textcolor = [UIcolor colorWithRed:0.191 green:0.264 blue:0.446 Alpha:1.000]; else cell.textLabel.textcolor = self.TitleAlternativeTextcolor; } else { path = @"DownAccessory"; cell.textLabel.textcolor = (self.TitleTextcolor == nil ? [UIcolor blackcolor] : self.TitleTextcolor); } UIImage* accessoryImage = [UIImage imagenamed:path]; UIImage* whiteAccessoryImage = [UIImage imagenamed:[[path stringByDeletingPathExtension] stringByAppendingString:@"White"]]; UIImageVIEw* imageVIEw; if (cell.accessoryVIEw != nil) { imageVIEw = (UIImageVIEw*) cell.accessoryVIEw; imageVIEw.image = (self.uSEOnlyWhiteImages ? whiteAccessoryImage : accessoryImage); imageVIEw.highlightedImage = whiteAccessoryImage; } else { imageVIEw = [[UIImageVIEw alloc] initWithImage:(self.uSEOnlyWhiteImages ? whiteAccessoryImage : accessoryImage)]; imageVIEw.highlightedImage = whiteAccessoryImage; cell.accessoryVIEw = imageVIEw; }}#pragma mark -#pragma mark Select Cell- (voID) dIDSelectCellAtRow:(NSUInteger)row { if (row == 0) { [self dIDSelectTitleCell]; } else [self dIDSelectContentCellAtRow:row - 1];}- (voID) dIDSelectTitleCell { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSData *myDecodedobject = [userDefaults objectForKey:@"tableVIEwDataPrevIoUs"]; NSMutableArray *decodedArray =[NSKeyedUnarchiver unarchiveObjectWithData: myDecodedobject]; NSLog(@"the back Up Count %d",[decodedArray count]); if ([decodedArray count]!=0){ NSLog(@"Back Up Array "); NSLog(@"am here herer hererer hererer %@ ",decodedArray); // it quit here [self.tableVIEw deleteRowsAtIndexPaths:decodedArray withRowAnimation:self.rowAnimation]; // [self.tableVIEw reloadData]; [self.tableVIEw endUpdates];// Nsstring *appDomain = [[NSBundle mainBundle] bundleIDentifIEr];// [[NSUserDefaults standardUserDefaults] removePersistentDomainForname:appDomain]; NSLog(@"am here herer hererer hererer"); } NSLog(@"dIDSelectedTitleCell"); self.open = !self.open; NSLog(@"1"); if (self.contentNumberOfRow != 0) [self setAccessoryVIEwOnCell:[self.tableVIEw cellForRowAtIndexPath:[self.tableVIEw indexPathForSelectedRow]]]; NSIndexPath* indexPath = [self.tableVIEw indexPathForSelectedRow]; NSUInteger section = indexPath.section; NSUInteger contentCount = self.contentNumberOfRow; [self.tableVIEw beginUpdates]; NSMutableArray* rowToInsert = [[NSMutableArray alloc] init]; for (NSUInteger i = 1; i < contentCount + 1; i++) { NSIndexPath* indexPathToInsert = [NSIndexPath indexPathForRow:i inSection:section]; [rowToInsert addobject:indexPathToInsert]; } if (self.open) { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSData *myDecodedobject = [userDefaults objectForKey:@"tableVIEwDataPrevIoUs"]; NSMutableArray *decodedArray =[NSKeyedUnarchiver unarchiveObjectWithData: myDecodedobject]; NSLog(@"the back Up Count %d",[decodedArray count]); if ([decodedArray count]!=0){ NSLog(@"Back Up Array "); [self.tableVIEw deleteRowsAtIndexPaths:decodedArray withRowAnimation:self.rowAnimation]; //[self.tableVIEw endUpdates]; Nsstring *appDomain = [[NSBundle mainBundle] bundleIDentifIEr]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForname:appDomain]; } [self.tableVIEw insertRowsAtIndexPaths:rowToInsert withRowAnimation:self.rowAnimation]; [self.tableVIEw endUpdates]; backUp = [[NSMutableArray alloc]init]; [backUp addobjectsFromArray:rowToInsert]; NSLog(@"the back Up Count %@",backUp ); NSData *myEncodedobject = [NSKeyedArchiver archivedDataWithRootObject:backUp]; [userDefaults setobject:myEncodedobject forKey:@"tableVIEwDataPrevIoUs"]; ; [userDefaults synchronize]; } else { [self.tableVIEw deleteRowsAtIndexPaths:rowToInsert withRowAnimation:self.rowAnimation]; [self.tableVIEw endUpdates];} [self.tableVIEw endUpdates]; if (self.open) [self.tableVIEw scrollToNearestSelectedRowAtScrollposition:UItableVIEwScrollpositiontop animated:YES]; [self.tableVIEw deselectRowAtIndexPath:indexPath animated:YES];}- (voID) dIDSelectContentCellAtRow:(NSUInteger)row {}@end
而输出是
2014-10-09 13:10:13.747 Brnlysta2[10199:90b] the back Up Count ( "<NSIndexPath: 0x8e8fb80> {length = 2,path = 0 - 1}","<NSIndexPath: 0x8e87900> {length = 2,path = 0 - 2}","<NSIndexPath: 0x8e871c0> {length = 2,path = 0 - 3}","<NSIndexPath: 0x8e908e0> {length = 2,path = 0 - 4}" ) 2014-10-09 13:10:14.717 Brnlysta2[10199:90b] index path section 1 indexrow 0 2014-10-09 13:10:14.718 Brnlysta2[10199:90b] the back Up Count 4 2014-10-09 13:10:14.718 Brnlysta2[10199:90b] Back Up Array 2014-10-09 13:10:14.719 Brnlysta2[10199:90b] am here herer hererer hererer ( "<NSIndexPath: 0x8b3bb60> {length = 2,"<NSIndexPath: 0x8b8e5c0> {length = 2,"<NSIndexPath: 0x8b75f60> {length = 2,"<NSIndexPath: 0x8b7b960> {length = 2,path = 0 - 4}" ) 2014-10-09 13:10:14.719 Brnlysta2[10199:90b] *** Assertion failure in -[UItableVIEw _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2935.137/UItableVIEw.m:1368 2014-10-09 13:10:14.722 Brnlysta2[10199:90b] *** Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'InvalID update: invalID number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5),plus or minus the number of rows inserted or deleted from that section (0 inserted,4 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,0 moved out).' *** First throw call stack: ( 0 CoreFoundation 0x017fe1e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x0157d8e5 objc_exception_throw + 44 2 CoreFoundation 0x017fe048 +[NSException raise:format:arguments:] + 136 3 Foundation 0x0115d4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 4 UIKit 0x00315f63 -[UItableVIEw _endCellAnimationsWithContext:] + 13402 5 UIKit 0x00326590 -[UItableVIEw _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 337 6 UIKit 0x0032660b -[UItableVIEw deleteRowsAtIndexPaths:withRowAnimation:] + 55 7 Brnlysta2 0x0000368e -[GCRetractableSectionController dIDSelectTitleCell] + 382 8 Brnlysta2 0x000034d7 -[GCRetractableSectionController dIDSelectCellAtRow:] + 71 9 Brnlysta2 0x00008f13 -[RootVIEwController tableVIEw:dIDSelectRowAtIndexPath:] + 531 10 UIKit 0x003279a1 -[UItableVIEw _selectRowAtIndexPath:animated:scrollposition:notifyDelegate:] + 1513 11 UIKit 0x00327b14 -[UItableVIEw _userSelectRowAtPendingSelectionIndexPath:] + 279 12 UIKit 0x0032c10e __38-[UItableVIEw touchesEnded:withEvent:]_block_invoke + 43 13 UIKit 0x0025b0aa ___afterCACommitHandler_block_invoke + 15 14 UIKit 0x0025b055 _applyBlockToCFArraycopIEdToStack + 403 15 UIKit 0x0025ae76 _afterCACommitHandler + 532 16 CoreFoundation 0x017c636e __CFRUNLOOP_IS_CALliNG_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 17 CoreFoundation 0x017c62bf __CFRunLoopDoObservers + 399 18 CoreFoundation 0x017a4254 __CFRunLoopRun + 1076 19 CoreFoundation 0x017a39d3 CFRunLoopRunspecific + 467 20 CoreFoundation 0x017a37eb CFRunLoopRunInMode + 123 21 GraphiCSServices 0x037a25ee GSEventRunModal + 192 22 GraphiCSServices 0x037a242b GSEventRun + 104 23 UIKit 0x0023df9b UIApplicationMain + 1225 24 Brnlysta2 0x0000669d main + 141 25 libdyld.dylib 0x01e43725 start + 0 ) libc++abi.dylib: terminating with uncaught exception of type NSException解决方法 当您执行编辑/更新UItableVIEw的 *** 作时,如果数据完整性仍然存在,它会检查一些dataSource方法.你有问题.在您的numberOfSectionsIntableVIEw或tableVIEw:numberOfRowsInSection:方法中,存在误算.在调用deleteRowsAtIndexPaths之前,还需要更新用于计算节/行计数的必要属性.
顺便说一句,在deleteRowsAtIndexPaths之后使用reloadData没有任何意义.它可能会干扰您的删除动画.
总结以上是内存溢出为你收集整理的ios – 无效更新:第0节中的无效行数,以NSException类型的未捕获异常终止全部内容,希望文章能够帮你解决ios – 无效更新:第0节中的无效行数,以NSException类型的未捕获异常终止所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)