2013-01-14 67 views
0

当我在AQGridView上调用insertItemsAtIndices时,项目重叠,而不是显示在其相关的网格中。它工作正常,如果我在GridView上调用reloadData,但我想一次只添加一个单元格。AQGridView insertItemsAtIndices项目重叠

我有portraitGridCellSizeForGridView实现,但它似乎并没有在插入调用后被调用。

下面是相关的代码中插入:

[self.cartItemArray addObject:cartItem]; 

[self.cartGridView beginUpdates]; 

[self.cartGridView insertItemsAtIndices:[NSIndexSet indexSetWithIndex:self.cartItemArray.count - 1] withAnimation:AQGridViewItemAnimationNone]; 

[self.cartGridView endUpdates]; 

这里的AQGridView委托方法:

- (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView { 

return _cartItemArray.count; 

} 

- (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index { 

static NSString * GridCellIdentifier = @"CartItemListViewCell"; 

CartItemListViewCell_iPad * cell = (CartItemListViewCell_iPad *)[gridView dequeueReusableCellWithIdentifier:GridCellIdentifier]; 

if (!cell) { 
    CGRect cellFrame = CGRectMake(0, 0, _cellWidth, _cellHeight); 
    cell = [[CartItemListViewCell_iPad alloc] initWithFrame:cellFrame reuseIdentifier:GridCellIdentifier]; 
} 

CartItem *cartItem = [_cartItemArray objectAtIndex:index]; 

[(CartItemListViewCell_iPad*)cell updateCartItem:cartItem]; 

return cell; 

} 


- (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView { 

return CGSizeMake(_cellWidth, _cellHeight); 
} 

- (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index { 

if (index >= _cartItemArray.count){ 
    return; 
} 

self.selectedItemIndex = index; 

[[NSNotificationCenter defaultCenter] postNotificationName:NotificationEditPrintSizeCartItem object:[_cartItemArray objectAtIndex:index]]; 

} 

下面是什么样子:

Example of cells overlapping

,你可以看到我在屏幕上使用两个AQGridView。我想知道这是否会导致问题?任何帮助表示赞赏。谢谢!

回答

0

好吧,刚刚解决它。通过代码搜索,我发现下面被称为在reloadData:

[_gridData setDesiredCellSize: [_dataSource portraitGridCellSizeForGridView: self]]; 

所以,现在我打电话reloadData之前,我添加任何东西给它。