Ios CollectionView数据源上的NSInternalInconsistencyException异常

Ios CollectionView数据源上的NSInternalInconsistencyException异常,ios,objective-c,Ios,Objective C,我正在尝试将静态数据添加到UiCollectionViewController中。 问题是在程序启动后,它给了我这个未捕获的异常 错误日志: 2014-03-27 19:13:35.519 Rss[5435:a0b] viewDidLoad 2014-03-27 19:13:35.521 Rss[5435:a0b] numberofsectionsInCOllectionView 2014-03-27 19:13:35.521 Rss[5435:a0b] numberOfItemInSectio

我正在尝试将静态数据添加到UiCollectionViewController中。 问题是在程序启动后,它给了我这个未捕获的异常 错误日志:

2014-03-27 19:13:35.519 Rss[5435:a0b] viewDidLoad
2014-03-27 19:13:35.521 Rss[5435:a0b] numberofsectionsInCOllectionView
2014-03-27 19:13:35.521 Rss[5435:a0b] numberOfItemInSection
2014-03-27 19:13:35.523 Rss[5435:a0b] *** Assertion failure in -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:], /SourceCache/UIKit_Sim/UIKit-2903.23/UICollectionView.m:1365
2014-03-27 19:13:35.530 Rss[5435:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the collection view's data source did not return a valid cell from -collectionView:cellForItemAtIndexPath: for index path <NSIndexPath: 0xa02eae0> {length = 2, path = 0 - 0}'
我在谷歌上搜索错误,但这一行什么也没有出现:“数据源没有返回有效的单元格”。
我已经通过拖动将datasource和delegate都设置为storyboard中的类。

我猜,
dequeueReusableCell…
返回nil,或者不是
UICollectionViewCell
(或子类)的东西。您是否在那一行之后放置了一个断点以查看返回的内容?@David这就是问题所在。在情节提要上未设置数据源和委托。你能回答这个问题吗。
#import "RootViewController.h"

#define kCustomRowCount     7


@interface RootViewController ()
@property (nonatomic, strong) NSMutableDictionary *imageDownloadsInProgress;
@end


@implementation RootViewController{
    NSMutableArray *array;
}

#pragma mark 

// -------------------------------------------------------------------------------
//  viewDidLoad
// -------------------------------------------------------------------------------
- (void)viewDidLoad
{
 NSLog(@"viewDidLoad");
    [super viewDidLoad];
    array = [[NSMutableArray alloc] init];
    [array addObject:@"User1"];
    [array addObject:@"User2"];
    [array addObject:@"User3"];
    [array addObject:@"User4"];
    [array addObject:@"User5"];
    [array addObject:@"User6"];
    [array addObject:@"User7"];
    [array addObject:@"User8"];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    NSArray *allDownloads = [self.imageDownloadsInProgress allValues];
    [allDownloads makeObjectsPerformSelector:@selector(cancelDownload)];

    [self.imageDownloadsInProgress removeAllObjects];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
     NSLog(@"numberofsectionsInCOllectionView");
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSLog(@"numberOfItemInSection");
    return [array count];
}


}
- (UICollectionViewCell *)collectionview:(UICollectionView *)collectionview cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"cellForItemAtIndexPath");


        UICollectionViewCell *cell = [collectionview dequeueReusableCellWithReuseIdentifier:@"CELL"
                                                                                forIndexPath:indexPath ];
    UILabel *label = (UILabel *)[cell viewWithTag:100];
    label.text = [array objectAtIndex:indexPath.row];
        return cell;
}

@end