gpt4 book ai didi

ios - xcode如何在数据库中的 Collection View 单元格中显示图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:23 25 4
gpt4 key购买 nike

我只是一个初学者。我想在 Collection View 单元格中显示存储在数据库中的图像。我已经创建了数据库和 Collection View 。我的代码如下,

MyDatabase *data;
data=[MyDatabase new];
imagearray=[data OpenMyDatabase:@"SELECT pic_name FROM exterior" :@"pic_name"];

所以我的问题是如何显示图像?让我知道方式/代码提前致谢

最佳答案

您可以使用以下代码显示 UIImage 网格。为您的 xib 文件添加 UICollectionView。不要忘记在集合中设置 delegate

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return noOfItem/ noOfSection;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return noOfSection;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";

UICollectionViewCell *cell =
[collectionView dequeueReusableCellWithReuseIdentifier:identifier
forIndexPath:indexPath];

UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [imageArray objectAtIndex:
(indexPath.section * noOfSection + indexPath.row)];

return cell;


}

在您的 xib 文件中,将 UIImageView 添加到您的 CollectionViewCell 并将其 tag 值更改为 100。

关于ios - xcode如何在数据库中的 Collection View 单元格中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15150721/

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