最初のキーを画像として持つ辞書の配列があります。データソースとして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 がデータ ソースです。残念ながら、インターネットで見つけた多くのチュートリアルでは、データ ソースとして 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 の使い方がわかりません。では、UIViewController で UICollectionView を使用するにはどうすればよいでしょうか。
ご協力ありがとうございました。
PS 以下はエラーメッセージです。
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'