TableViewCell内にCollectionViewを置く
xibでTableViewCellを作成し、そのTableViewCellの内にCollectionViewを置きました。次にそのCollectionViewの中にCollectionViewCellを置こうとするのですが、なぜかセルを置くことができません。StoryboardのUIViewControllerにCollectionViewを置いてCollectionViewCellを置くと、ちゃんと置くことができます。また、StoryboardではCollectionViewを置くとCollectionViewの背景が真っ黒な状態で追加されるのですが、xibでCollectionViewを置くと、初めからセルが網目のように追加された状態で置かれます。ということはxibではCollectionViewの中にCollectionViewCellを置くことができないのでしょうか?CollectionViewCellが置けないので、Storyboard上でセルのidentifierが設定できず少し困っています。
---追記---
ViewController.m
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UINib *nib = [UINib nibWithNibName:NSStringFromClass([CustomCell class]) bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"cell"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
-(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
@end
CustomCell.m
@implementation CustomCell
- (void)awakeFromNib {
[super awakeFromNib];
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[CustomCell class] forCellWithReuseIdentifier:@"collectionCell"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 3;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
return cell;
}