ios - 将布局更改为自定义类后 UicollectionViewCell 未显示

标签 ios objective-c uicollectionview

我正在使用 RFQuiltLayout用于我的 uicollectionview

我的 Storyboard包含 Uiview + collectionview。 collectionview 是我的 UiView 类的 IBOutleted ,在我的 Storyboard中,我为我的 collectionview 使用自定义布局,如下所示:

enter image description here

我正在从 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/

相关文章:

ios - 重复使用 UICollectionView 中的单元格时,会短暂显示重复使用的 UICollectionViewCell 的旧内容

ios - swift 将 View 设置为自己的委托(delegate)

ios - UISlider 导致水平滚动

iphone - iPhone 和 iPad 的 Assets 命名

ios - iOS View 上的自定义 subview 有空 socket

ios - 具有 collectionView 性能问题的 TableView 单元格

iOS网络应用程序: Use back swipe gesture to go back

ios - Crashlytics pod 仍在使用 UIWebView 生成 ITMS-90809 : Deprecated API Usage

iphone - 如何让我的 iPhone 应用程序在 iPad 上运行?

ios - 从 coredata 接收图像