【发布时间】:2016-04-04 05:40:15
【问题描述】:
我有一个 UICollectionView 有 5 个部分,有些部分有数据,有些部分(在我的代码中是第 2 部分)没有(取决于服务器)
因此,我想在没有数据的选择中显示一个标签(“No item”)。
但是,我可以找到任何想法来做到这一点,我希望任何人都可以给我一些建议或指导来实现它。
我真的很感激任何帮助
这是我的跨级部分代码
-(UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
FriendsFanLevelHeaderView *headerView = (FriendsFanLevelHeaderView *)[self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FanLevelHeader" forIndexPath:indexPath];
switch (indexPath.section) {
case 0:
[headerView.lblFanLevelTitle setText:@"Gold"];
break;
case 1:
[headerView.lblFanLevelTitle setText:@"Silver"];
break;
case 2:
[headerView.lblFanLevelTitle setText:@"Bronze"];
break;
case 3:
[headerView.lblFanLevelTitle setText:@"Green"];
break;
case 4:
[headerView.lblFanLevelTitle setText:@"Other"];
break;
default:
break;
}
return headerView;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
switch (section) {
case 0:
return 3;
case 1:
return 0; // it doesn't have any item
case 2:
return 2;
case 3:
return 3;
case 4:
return 5;
default:
return 0;
}
}
- (FriendsCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
FriendsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FriendsCollectionViewCell" forIndexPath:indexPath];
[cell.lblFriendBand setText:@"Band: White Mash "];
[cell.lblFriendGenre setText:@"Freestyle house, House, Freestyle music,"];
[cell.lblFriendECScore setText:@"EC score: 79"];
return cell;
}
==============================================
这就是我想要的
【问题讨论】:
-
您是否获取数组格式的数据.. ??
-
是的,我的数据是数组格式
-
你的意思是子数组的数组..??
-
我是 iOS 新手,我不知道不同的 beetween 数组和子数组。我正在使用 NSMutableArray
-
我已经添加了我的 ans ,检查并告诉我它是否有效。
标签: ios objective-c collectionview