UITableViewCell cell中創(chuàng)建UICollectionView
//UITableViewCell 賦值
if (self.provinceArray.count) {
for (NSDictionary *dataDic in self.provinceArray) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dataDic];
//設(shè)置第一個(gè)為選擇狀態(tài)
[dic setObject:@"0" forKey:@"selected"];
[cell.dataArray addObject:dic];
}
[[cell.dataArray objectAtIndex:0] setObject:@"1" forKey:@"selected"];
}
//UICollectionViewCell 復(fù)用方法中
- (UICollectionViewCell )collectionView:(UICollectionView)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dataDic = [self.dataArray objectAtIndex:indexPath.item];
CJWProvinceCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CJWProvinceCollectionViewCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor clearColor];
[cell.provinceBtn setTitle:emptyString([dataDic objectForKey:@"name"]) forState:UIControlStateNormal];
if ([[dataDic objectForKey:@"selected"] isEqualToString:@"1"]) {
cell.provinceBtn.selected = YES;
}else{
cell.provinceBtn.selected = NO;
}
return cell;
}
//點(diǎn)擊UICollectionViewCell的方法
-
(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
for (int i = 0;i<self.dataArray.count; i++) {
NSDictionary *dic = self.dataArray[i];
[dic setValue:@"0" forKey:@"selected"];
}
NSDictionary *dic = self.dataArray[indexPath.item];
[dic setValue:@"1" forKey:@"selected"];
NSString *provinceId = emptyString([[self.dataArray objectAtIndex:indexPath.item] objectForKey:@"code"]);if (_delegate && [_delegate respondsToSelector:@selector(selectedProvinceRequestFeatureList:)]) {
[_delegate selectedProvinceRequestFeatureList:provinceId];
}
[self.collectionView reloadData];
}