gpt4 book ai didi

ios - 以 UIViewController 作为数据源的 UICollectionView

转载 作者:行者123 更新时间:2023-11-28 18:38:04 24 4
gpt4 key购买 nike

我有一个字典数组,第一个键作为图像。我使用 UIViewController 作为数据源。

@interface myViewController () {
NSMutableArray *textureArray1;
NSMutableDictionary *dict1;
UIImage *key1a; // UIImage
NSString *key1b; // texture name
}

我可以轻松地使用 UIViewController 中布置的 TableView 控件填充此字典数组。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
UIImage *image = [[textureArray1 objectAtIndex:indexPath.row] objectForKey:key1a];
cell.textLabel.text = [[textureArray1 objectAtIndex:indexPath.row] objectForKey:key1b];
cell.imageView.image = image;
return cell;
}

我想做点新的。我想用 UICollectionView 填充相同的图像数组,其中 UIViewController 是数据源。不幸的是,我在 Internet 上找到的许多教程都将 UICollectionViewController 作为数据源。无论如何,我有以下代码行。

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithPatternImage:[[textureArray1 objectAtIndex:indexPath.row] objectForKey:key1b]];
return cell;
}

应用程序崩溃并显示“无法识别的选择器已发送到实例...”错误,好吧,我不知道如何使用 UICollectionView。那么如何将 UICollectionView 与 UIViewController 一起使用呢?

感谢您的帮助。

附言以下是错误信息。

2013-03-20 10:21:07.777 iPadapp[2023:c07] -[__NSCFString _tiledPatternColor]: unrecognized selector sent to instance 0xdeacdf0
2013-03-20 10:21:07.778 iPadapp[2023:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _tiledPatternColor]: unrecognized selector sent to instance 0xdeacdf0'

最佳答案

您需要在 header 中说明您的 UIViewControllerUICollectionViewDataSourceUICollectionViewDelegateSee this answer

关于ios - 以 UIViewController 作为数据源的 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15516427/

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