gpt4 book ai didi

ios - UIcollectionView Controller 中没有任何内容

转载 作者:行者123 更新时间:2023-11-28 20:04:22 24 4
gpt4 key购买 nike

我在 Uinavigationviewcontroller 之后的第一个应用程序 View 中有 UIcollectionView 就在 Storyboard中,就像这样:

enter image description here

这是我的 RootViewController.h

#import <UIKit/UIKit.h>
@interface RootViewController : UICollectionViewController<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSArray *entries;
@end

和我的 RootViewController.m :

#import "RootViewController.h"
#import "AppRecord.h"
#import "Cell.h"
#define kCustomRowCount 7


@interface RootViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
// the set of IconDownloader objects for each app
@property (nonatomic, strong) NSMutableDictionary *imageDownloadsInProgress;
@end


@implementation RootViewController

#pragma mark

// -------------------------------------------------------------------------------
// viewDidLoad
// -------------------------------------------------------------------------------
- (void)viewDidLoad
{
NSLog(@"inside class");
[super viewDidLoad];
// self.title = @"My Title";

//self.collectionView.delegate = self;
//self.collectionView.dataSource=self;

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSUInteger count = [self.entries count];
NSLog(@"count: %lu", (unsigned long)count);

if (count == 0)
{
return kCustomRowCount;
}
return count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

NSLog(@"inside cell");
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];
UIImage *truckImage = [[UIImage alloc] init];
truckImage = [UIImage imageNamed:@"Default.png"];
cell.imageView.image = truckImage;
return cell;
}

@end

现在的问题是我的“cellForItemAtIndexPath”或“numberOfItemsInSection”甚至“viewDidLoad”都没有被调用,模拟器上的输出是黑屏。

这是我的 AppDelegate 类的重新加载部分:

    __block ParseOperation *weakParser = parser;

parser.completionBlock = ^(void) {
if (weakParser.appRecordList) {
dispatch_async(dispatch_get_main_queue(), ^{
RootViewController *rootViewController = (RootViewController*)[(UINavigationController*)self.window.rootViewController topViewController];

rootViewController.entries = weakParser.appRecordList;
if(weakParser.appRecordList != nil)
NSLog(@"weakParser.appRecordList is Not nill");
[rootViewController.collectionView reloadItemsAtIndexPaths:[rootViewController.collectionView indexPathsForVisibleItems]];
[rootViewController.collectionView reloadData];
});
}

self.queue = nil;
};

[self.queue addOperation:parser];
self.appListData = nil;
}

最佳答案

您是否为 Collection View 添加了委托(delegate)和数据源连接?通常,这是最常见的错误。他们在代码中被注释掉了,我假设你是通过 Storyboard 做到的

关于ios - UIcollectionView Controller 中没有任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22607749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com