我正在使用 RFQuiltLayout用于我的 uicollectionview
。
我的 Storyboard包含 Uiview
+ collectionview
。 collectionview 是我的 UiView
类的 IBOutleted
,在我的 Storyboard中,我为我的 collectionview 使用自定义布局,如下所示:
我正在从 appdelegate
类加载我的 collectionview 数据,因此在第一次运行时,它会为 numberOfItemsInSection
返回 0
,并且在从服务器获取数据后它将加载我的 Collection View 。
现在的问题是,如果我将布局更改为流程程序可以正常工作,但如果我使用像 RFQuiltLayout
这样的自定义类,则不会显示单元格,
numberOfItemsInSection 返回我的实际值,但 cellForItemAtIndexPath 没有被调用。
我的ViewDidLoad
中的代码:
self.CV.delegate = self;
self.CV.dataSource = self;
[self.CV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MyCell"];
RFQuiltLayout* layout = (id)[self.CV collectionViewLayout];
layout.direction = UICollectionViewScrollDirectionVertical;
layout.blockPixels = CGSizeMake(75,75);
我还在 viewDidAppear
中调用 reloaddata
。
在appdelegate
中:
ParseOperation *weakParser = parser;
parser.completionBlock = ^(void) {
if (weakParser.appRecordList) {
dispatch_async(dispatch_get_main_queue(), ^{
MyCollectionViewController *rootViewControllers = (MyCollectionViewController*)[(UINavigationController*)self.window.rootViewController topViewController];
rootViewControllers.entries = weakParser.appRecordList;
[rootViewControllers.CV.collectionViewLayout invalidateLayout];
[rootViewControllers.CV reloadData];
});
}
有一件事是,如果我在委托(delegate)中使用此代码,uicollection 会显示,但没有任何自定义布局和滚动功能:
[rootViewControllers.CV reloadData];
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
NSIndexPath *indexPath;
for (int i = 0; i < [weakParser.appRecordList count]; i++) {
indexPath = [NSIndexPath indexPathForItem:i inSection:0];
[indexPaths addObject:indexPath];
}
[rootViewControllers.CV reloadItemsAtIndexPaths:indexPaths];
RFQuiltLayout 内部的方法被调用,但内部布局的方法被调用
像这些“blockSizeForItemAtIndexPath”和
的uiview“blockSizeForItemAtIndexPath”没有被调用。
最佳答案
您不需要在您的 didload 中再次注册该类。我想这就是你的问题背后的原因。转到 Storyboard 并选择 CollectionViewCell
并将其类更改为您的自定义类。并从您的 didLoad [self.CV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MyCell"] 中删除这一行;
关于ios - 将布局更改为自定义类后 UicollectionViewCell 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28936504/