I have an array of dictionary with the first key as an image. I'm using UIViewController as the data source.
@interface myViewController () {
NSMutableArray *textureArray1;
NSMutableDictionary *dict1;
UIImage *key1a; // UIImage
NSString *key1b; // texture name
}
I don't have trouble populating this dictionary array with a TableView control laid out in the UIViewController.
- (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;
}
I want to do something new. And I want to populate the same array of images with UICollectionView where, again, UIViewController is the data source. Unfortunately, many tutorials that I find on the Internet have UICollectionViewController as the data source. Anyway, I have the following lines of code.
-(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;
}
And the application crashes with an error that says "unrecognized selector sent to instance..." Well, I don't know how to use UICollectionView. So how do you use UICollectionView with UIViewController?
Thank you for your help.
P.S. The following is the error message.
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'