그래서 iOS 프로그래밍을 조금 해보았습니다. 많은 시간을 들이지는 마라. 그러나 나는 너무 오랫동안 그것을 배우기 위해 연기하고 있었다. 하지만이 괴물 같은 문제로 2 일 동안 고생했습니다. 내 collectionView 셀을 추가하려고하면 다음 오류가 발생합니다.iOS CollectionView 'NSInternalInconsistencyException'
'NSInternalInconsistencyException', 이유 :
@interface DocumentsViewController() {
FileManager *fileManager;
NSMutableArray *folderContent;
}
@end
@implementation DocumentsViewController
@synthesize fileList;
- (void)viewDidLoad
{
[super viewDidLoad];
folderContent = [[NSMutableArray alloc] init];
fileManager = [[FileManager alloc] init];
NSArray *items = [fileManager getDirectoryInfo];
[self createFileList:items];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)createFileList:(NSArray *)items
{
for(NSString *item in items)
{
NSInteger count = [folderContent count];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:count inSection:0];
[folderContent insertObject:item atIndex:count];
[self.fileList insertItemsAtIndexPaths:@[indexPath]];
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
FilesViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DefaultCell" forIndexPath:indexPath];
cell.image.image = [UIImage imageNamed:@"folder.png"];
cell.label.text = @"oi"; //objects[indexPath.row];
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return folderContent.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
@end
감사에서 : '섹션 0으로 항목에 0을 삽입하려고하지만 업데이트 이후 섹션 0 만 0 항목이'여기
내 코드입니다 미리, 루카스
업데이트
확인하므로 후에 FE w 매우 유용한 팁, 다른 오류 메시지가 나타납니다. 'NSInternalInconsistencyException', 이유 : '잘못된 업데이트 : 0 번 항목의 항목 수가 잘못되었습니다. 업데이트 (1) 이후에 기존 섹션에 포함 된 항목의 수는 업데이트 (1) 이전에 해당 섹션에 포함 된 항목 수, 해당 섹션에서 삽입 또는 삭제 된 항목 수를 더한 값 (삽입 된 값 1, 삭제 된 값 0) 및 해당 섹션 안팎으로 이동 한 항목 수를 더한 값 또는 빼기 값 0은 움직 였고, 0은 밖으로 움직였다). '
나는 아래에서 말했듯이 (NSInteger) collectionView : (UICollectionView *) collectionView numberOfItemsInSection : (NSInteger) 섹션이 두 번 연속으로 호출 되었기 때문에 folderContent.count의 값에 시간을주지 않아도됩니다. 변화.
'self.fileList.dataSource'가'self'로 설정되어 있습니까? 'createFileList :'와'collectionView : numberOfItemsInSection :'에 중단 점을 넣으십시오. 두 중단 점에서'self'와'folderContent'가 같은 (non-nil) 값으로 설정되어 있는지 확인하십시오. –
나는 Sean이 말한 바를 고쳤으며 링크 문제를 수정하여 오류가 변경되었습니다. 그래서 앱을 디버깅하고있었습니다. collectionView : numberOfItemsInSection이 두 번 호출되고 반환 값 (folderContent.count)이 1이면 응용 프로그램이 중단됩니다. 나는 앱 스택 경로가 올바르게되지 않을 수도 있다고 생각한다. –