gpt4 book ai didi

ios - UICollectionView 显示为空白

转载 作者:行者123 更新时间:2023-11-29 01:03:24 27 4
gpt4 key购买 nike

我正在尝试使用 UICollectionView,但我遇到了很多问题。我有一个 UIViewController 里面有一个 UICollectionView。我已经正确设置了所有代表以及 CVcell 中的 UILabel。 View 出现并且是代码中定义的白色。 NSLog 发送了所有单元格和应该存在的文本,但在实际的 UICollectionView 中它是空白的,除了 ScrollView 之外没有任何内容出现。我已经尝试了一切,但似乎无法正常工作。该单元格为 187 x 187,占据屏幕尺寸的一半,中间有一个标签。我将在下面发布代码。

谢谢

Delegate

#import "StudentControllerMain.h"
#import "CVcell.h"



@interface StudentControllerMain ()
@property (nonatomic, strong) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *dataArray;


@end

@implementation StudentControllerMain





- (void)viewDidLoad {
[super viewDidLoad];

NSMutableArray *firstSection = [[NSMutableArray alloc] init];


for (int i=0; i<5; i++) {
[firstSection addObject:[NSString stringWithFormat:@"Cell %d", i]];
}

self.dataArray = [[NSArray alloc] initWithObjects:firstSection, nil];




[self.collectionView registerClass:[CVcell class] forCellWithReuseIdentifier:@"CVcell"];


// Configure layout

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
self.collectionView = nil;
self.dataArray = nil;
// Dispose of any resources that can be recreated.
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}

/*
#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.
}
*/




-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return [self.dataArray count];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

NSMutableArray *sectionArray = [self.dataArray objectAtIndex:section];
return [sectionArray count];


}

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

// Setup cell identifier
static NSString *cellIdentifier = @"CVcell";
CVcell *cell = (CVcell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
NSMutableArray *data = [self.dataArray objectAtIndex:indexPath.section];
NSString *cellData = [data objectAtIndex:indexPath.row];
NSLog(cellData);
[cell.title setText:cellData];
[cell.title setTextColor:[UIColor blackColor]];

return cell;

}


@end

最佳答案

  1. 去除注册类代码;
  2. 在 Storyboard中设置 Collection View 单元格的“标识符”属性(在属性检查器中);

关于ios - UICollectionView 显示为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36725271/

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