【问题标题】:UICollectionView and UICollectionViewCell not functioningUICollectionView 和 UICollectionViewCell 不起作用
【发布时间】:2017-12-02 03:21:20
【问题描述】:

我正在尝试创建自己的自定义 UICollectionView 首先,我在 Storyboard 中添加了一个 CollectionView。

PURPLE 的原因是因为一开始我的控制器根本没有显示。因此,我将 CELL 设为灰色,并注意到在将 Collection View 设为紫色后,该项目不可见。

我正在尝试使用独特的图像和标签填充我的收藏视图。这是我旅程的开始。

这是我的 CollectionViewController

#import "LoadZoneViewController.h"
#import "ZoneCollectionViewCell.h"

@interface LoadZoneViewController ()

@end

@implementation LoadZoneViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];



    // Register cell classes
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
    return 12;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
    return 12;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];



    // Configure the cell

    return cell;
}

#pragma mark <UICollectionViewDelegate>


@end

我也定义了一个自定义 UICollectionViewCell,但我认为我应该担心我解决了这个问题之后。当前的问题只是标签没有出现,视图底部有一个滚动条,但我没有看到 12 个标签。

【问题讨论】:

  • 尝试在 viewdidload 中添加 self.collectionView.delegate = selfself.collectionView.dataSource = self
  • 好的,我试过了。仍然没有结果。

标签: ios objective-c uicollectionview


【解决方案1】:

尝试将委托添加到您的类界面

@interface LoadZoneViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

将此添加到您的viewDidLoad

[CollView registerNib:[UINib nibWithNibName:@"ZoneCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"YourCellIdentifier"];

在您的cellForItemAtIndexPath 中执行此操作

NSString *identifier = @"YourCellIdentifier";
ZoneCollectionViewCell *cell = (ZoneCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    • 2018-03-26
    • 2013-06-13
    相关资源
    最近更新 更多