知乎 日报
创始人
2024-02-03 23:15:52

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 评论界面
  • 首页cell的小标题的文字显示
  • 下拉刷新


前言

这周完成了评论内容,改了一些小bug。收藏界面正在加油,FMDB库目前不是很理解


评论界面

在这里插入图片描述
在这里插入图片描述

关于长评论和短评论,我是把他们分成了三个section。第一个section是长评论,第二个section是短评,第三个section是@“已加载全部评论”
第一个section的小标题就是请求到的数据中的长评论的个数,第二个section的小标题就是请求到的数据中短评的个数。
cell的高度我是通过计算对应的文字的行数,然后将行数存到数组里,在返回数组。根据对应的行数来计算对应cell的高度这样子实现

这里是cell上文字高度的计算

labText.numberOfLines = 0;[labText sizeToFit];CGFloat height = labText.frame.size.height;int num = height/labText.font.lineHeight;NSString* strHeight = [NSString stringWithFormat:@"%d", num];[self.longHeightArray addObject:strHeight];labText.numberOfLines = num + 10;NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc] init];paragraphStyle.lineSpacing = 10;NSMutableDictionary* attributes = [NSMutableDictionary dictionary];[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];labText.attributedText = [[NSAttributedString alloc] initWithString:labText.text attributes:attributes];

这里是cell的各个section和各个高度的返回

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{if (section == 0){return [self.LongCommentDictionary[@"comments"] count];} else if (section == 1){return [self.shortCommentDictionary[@"comments"] count];} else {return 1;}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    int i = 0;
//    int m = 0;if (indexPath.section == 0 ){NSString* strHeight = self.longHeightArray[indexPath.row];int num = [strHeight intValue];return (num * 20 + 90);} else if (indexPath.section == 1 && indexPath.row < self.shortHeightArray.count){NSString* strHeight = self.shortHeightArray[indexPath.row];int num = [strHeight intValue];return (num * 20 + 90);} else{return 100;}return 0;
}
- (void)addView{[self addSubview:self.commentTableView];
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;header.contentView.backgroundColor= [UIColor clearColor];header.textLabel.font = [UIFont boldSystemFontOfSize:20];header.textLabel.textColor = [UIColor blackColor];if (section == 0){NSString* str = [NSString stringWithFormat:@"%lu条长评", [self.LongCommentDictionary[@"comments"] count]];header.textLabel.text = str;} else if (section == 1){NSString* str = [NSString stringWithFormat:@"%lu条短评", [self.shortCommentDictionary[@"comments"] count]];header.textLabel.text = str;}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {return @"111";
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{if (section == 2){return 0;} else{return 20;}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{if (section == 2){return 0;} else{return 20;}
}

首页cell的小标题的文字显示

之前写的发现有bug,每次下拉刷新后请求到了前一天的日期,但是每次下拉后改变了所有section的标题,不是一个section的标题
重新使用了一种方法去写这块

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{if (section != 0 && section != self.addSection - 1 && section != 1){NSString* str = self.allCellArray[section - 2][@"date"];NSString* strNew = [str substringFromIndex:4];NSString* dateOne = [strNew substringToIndex:2];NSString* dateTwo = [strNew substringFromIndex:2];NSString* date = [NSString stringWithFormat:@"   %@月%@日---------------------------", dateOne, dateTwo];UILabel* lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 30, 40)];lab.textColor = [UIColor grayColor];lab.text = date;[lab setFont:[UIFont systemFontOfSize:25]];return lab;}return 0;
}- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{if (section != self.addSection - 1){return @"111";} else{return 0;}
}

在这里插入图片描述

下拉刷新

发现下拉刷新的bug是下拉三次以上的时候,请求到的两个section的cell就成了相同的。采用大佬的方法,将每次请求到的数据加到一个array里,然后这个cell上的各种信息使用这个array中的数据

- (void)GetBefore{NSString* dateOld = self.allCellArray[self.addSection - 4][@"date"];NSDictionary* dic = [NSDictionary dictionaryWithObject:dateOld forKey:@"111"];NSNotification* notification = [NSNotification notificationWithName:@"tongzhi" object:nil userInfo:dic];[[NSNotificationCenter defaultCenter] postNotification:notification];//[self.tableView reloadData];}
- (void)GetBefore{[[OldManager shareManger]makeData:^(HomeModel * _Nonnull ViewModel) {self.viewHome.stroiesDictionary = [ViewModel toDictionary];[self.viewHome.allCellArray addObject:self.viewHome.stroiesDictionary];dispatch_async(dispatch_get_main_queue(), ^{[self.viewHome.tableView reloadData];});} error:^(NSError * _Nonnull error) {NSLog(@"请求失败!");}date:(NSString*)self.oldDate];}
else if (indexPath.section != 0 ){//在这里进行相应的布局}

收藏界面FMDB库暂时没看明白。正在加油

相关内容

热门资讯

埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...
脚上的穴位图 脚面经络图对应的... 人体穴位作用图解大全更清晰直观的标注了各个人体穴位的作用,包括头部穴位图、胸部穴位图、背部穴位图、胳...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...
猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
demo什么意思 demo版本... 618快到了,各位的小金库大概也在准备开闸放水了吧。没有小金库的,也该向老婆撒娇卖萌服个软了,一切只...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...