gpt4 book ai didi

ios - UICollectionview 为空

转载 作者:可可西里 更新时间:2023-11-01 06:17:52 29 4
gpt4 key购买 nike

您好,我创建了一个 UIViewController,其中添加了一个带有 CustomCell 的 UICollectionView。然后,我为单元格创建了一个 uicollectionviewcell 类。最后在故事情节本身中设置委托(delegate)和数据源。但它显示空白页面。如下图所示

enter image description here

代码:

- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionview = _collectionview;
self.collectionview.dataSource = self;
self.collectionview.delegate = self;

speakersImages=[[NSMutableArray alloc]init];
// Do any additional setup after loading the view, typically from a nib.
imageLabels=[[NSMutableArray alloc]initWithObjects:@"RB Forum 2013",@"Agenda",@"Speakers",@"Contact",@"Map",@"Websites",@"@Responsible Biz",@"Partners",@"Sustainability",nil];


imagePaths=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"RBform.png"],[UIImage imageNamed:@"agenda.png"],[UIImage imageNamed:@"speakers.png"],[UIImage imageNamed:@"contact.png"],[UIImage imageNamed:@"map.png"],[UIImage imageNamed:@"website.png"],[UIImage imageNamed:@"twitter.png"],[UIImage imageNamed:@"partners.png"],[UIImage imageNamed:@"sustainability.png"], nil];
[self.collectionview registerClass:[NewCell class] forCellWithReuseIdentifier:@"Cell"];



}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return [imageLabels count];
}

//THE BELOW DELEGATE METHOD DOES NOT GET CALLED!


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// we're going to use a custom UICollectionViewCell, which will hold an image and its label
//
static NSString *CellIdentifier = @"Cell";
NewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

// make the cell's title the actual NSIndexPath value

cell.labels.text = [NSString stringWithFormat:@"%@",[imageLabels objectAtIndex:indexPath.row]];
// load the image for this cell
NSLog(@"%@",imageLabels);
//NSString *imageToLoad = [NSString stringWithFormat:@"%d.JPG", indexPath.row];
// cell.image.image = [UIImage imageNamed:imageToLoad];
cell.images.image = [imagePaths objectAtIndex:indexPath.row];

return cell;

}

enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

解决方案已删除[self.collectionview registerClass:[NewCell class] forCellWithReuseIdentifier:@"Cell"];

在 storybord 中我们不需要这个

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

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