UI今天給了個(gè)需求,把亂序的單詞拼成一句話节吮,如下圖:
哈哈,這個(gè)的確就是當(dāng)時(shí)的想法判耕,不要慫就是干~
那就來試試吧透绩,話不多說,直接上代碼:
-(UITableView*)tagsView{
? ? if (!_tagsView){
? ? ? ? _tagsView =[[UITableView alloc]initWithFrame:CGRectMake(0, 239, kScreenWidth, kScreenHeight/2-60) style:UITableViewStylePlain];
? ? ? ? _tagsView.alwaysBounceVertical = YES;
? ? ? ? _tagsView.delegate=self;
? ? ? ? _tagsView.dataSource=self;
? ? }
? ? return _tagsView;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
? ? return self.groups.count;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
? ? EFTagGroupItem*group =self.groups[section];
? ? returngroup.data.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
? ? if(indexPath.section==0) {
? ? ? ? EFHobbyCell *cell = [tableView dequeueReusableCellWithIdentifier:hobbyCell];
? ? ? ? cell.tagList=self.tagList;
? ? ? ? returncell;
? ? }
? ? EFGroupItem*group =self.groups[indexPath.section];
? ? EFTagGroupItem*tagGroup = group.data[indexPath.row];
? ? EFTagGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:tagGroupCell forIndexPath:indexPath];
? ? cell.collectionView.delegate = self;
? ? cell.tagGroup= tagGroup;
? ? returncell;
}
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
? ? if(indexPath.section==0) {
? ? ? ? return _tagList.tagListH;
? ? }
? ? EFGroupItem*group =self.groups[indexPath.section];
? ? EFTagGroupItem*tagGroup = group.data[indexPath.row];
? ? returntagGroup.cellH;
}
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
? ? return 0;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath
{
? ? EFTagCell*cell = (EFTagCell*)[collectionViewcellForItemAtIndexPath:indexPath];
? ? EFTagsItem*item = cell.item;
? ? item.isSelected = !item.isSelected;
? ? cell.item= item;
? ? NSString*tagStr = cell.tagLabel.text;
? ? if(item.isSelected) {
? ? ? ? [self.tagListaddTag:tagStr];
? ? ? ? [self.selectTagDictsetObject:cellforKey:tagStr];
? ? ? ? [self.selectTagArraddObject:tagStr];
? ? }else{
? ? ? ? [self.tagListdeleteTag:tagStr];
? ? ? ? for(inti =0;i<_selectTagArr.count;i++){
? ? ? ? ? ? if([_selectTagArr[i]isEqualToString:tagStr]){
? ? ? ? ? ? ? ? [_selectTagArrremoveObjectAtIndex:i];
? ? ? ? ? ? ? ? i--;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? [self.tagsView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
}
很簡(jiǎn)單的需求壁熄,有不懂的可以線下交流 wx:dwl-1591293009