2


我有一个 AQGridView ,网格的“初始化”效果很好,但是当我这样做时[gridView reloadData],它会因错误而崩溃

2012-01-03 21:27:40.338 XXX[8454:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key'

经过几次尝试后,我跟踪到来自 AQGridView 的错误enqueueReusableCells。它试图获得cell.reuseIdentifier它的价值是nil出于某种奇怪的原因。

这是 gridView:cellForItemAtindex 的代码:

- (AQGridViewCell *)gridView:(AQGridView *)aGridView cellForItemAtIndex:(NSUInteger)index{
    static NSString *CellIdentifier = @"SocialCell";
    SocialCell *cell = (SocialCell *) [gridView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil){
        cell = [[SocialCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SocialCell" owner:nil options:nil];

        for(id currentObject in topLevelObjects){
            if([currentObject isKindOfClass:[SocialCell class]]){
                cell = (SocialCell *)currentObject;
                break;
            }
        }
    }

正如我所说,第一次运行效果很好,但第二次运行(重新加载数据)没有按预期工作。这个视图总共包括 7 个单元格,所以它甚至没有真正出队,所以我不确定为什么这个值会是 nil 并崩溃。

将不胜感激这方面的任何信息:) 谢谢!

4

0 回答 0