提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
这周完成了评论内容,改了一些小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;}
}
之前写的发现有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库暂时没看明白。正在加油
上一篇:分析高数值孔径物镜的聚焦特性
下一篇:编码命名方式知多少