【问题标题】:Don't show UICollectionViewController [duplicate]不显示 UICollectionViewController [重复]
【发布时间】:2015-10-26 17:31:56
【问题描述】:

我正在尝试在 Xcode 6 上使用 UICollectionViewController,但我看不到自定义单元格或原型项目。我把标签放在白色的单元格中,我实现了 numberOfSections 和 numberOfItemsInSection 但问题仍然存在。可以帮我?提前致谢。

@implementation CollectionViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;

    // 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 - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

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


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete method implementation -- Return the number of items in the section
    return 5;
}

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

    // Configure the cell

    return cell;
}

【问题讨论】:

    标签: ios objective-c xcode xcode6


    【解决方案1】:

    您好,请尝试在以下位置设置一些数据:cellForItemAtIndexPath

    我的代码的小例子

    - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        MEMediaView *cell =  [cv dequeueReusableCellWithReuseIdentifier:@"MEMediaView" forIndexPath:indexPath];
        [cell awakeFromNib];
        [cell setMemryMediaData:[mediaArray_ objectAtIndex:indexPath.row]];
        [cell setMediaContent];
        if (shadow)
        {
            [cell shadeCoverImage];
        }
    
        return cell;
    }
    

    别忘了设置委托:

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

    【讨论】:

    • 我编辑了我的未发誓请尝试
    • 我在 Connection Inspector 上有这个,我不知道为什么会出现这个问题,UITableViewController 没问题,但是 UICollectionViewController 我显示黑屏,我用原型单元格更改背景颜色但问题仍然存在。跨度>
    • 解决方法是删除 [self.collectionview registerClass:[NewCell class] forCellWithReuseIdentifier:@"Cell"];在情节提要中,我们不需要这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多