当前位置: 首页 > news >正文

做网站模板用什么框架媒体:北京不再公布各区疫情数据

做网站模板用什么框架,媒体:北京不再公布各区疫情数据,建设信用中国网站的目的,做网站muse好还是DW好用文章目录 一、评论区展开与收缩二、FMDB库实现本地持久化FMDB常用类:FMDB的简单使用: 三、点赞和收藏的持久化 一、评论区展开与收缩 有的评论没有被回复评论或者被回复评论过短,这时就不需要展开全文的按钮,所以首先计算被回复评…

文章目录

  • 一、评论区展开与收缩
  • 二、FMDB库实现本地持久化
      • FMDB常用类:
      • FMDB的简单使用:
  • 三、点赞和收藏的持久化


一、评论区展开与收缩

有的评论没有被回复评论或者被回复评论过短,这时就不需要展开全文的按钮,所以首先计算被回复评论的文本高度,根据文本高度来决定是否隐藏展开全文的按钮。

CGSize constrainedSize = CGSizeMake(WIDTH - 70, CGFLOAT_MAX); // labelWidth为UILabel的宽度,高度设置为无限大NSDictionary *attributes = @{NSFontAttributeName: cell.replyLabel.font}; // label为要计算高度的UILabel控件CGRect textRect = [cell.replyLabel.text boundingRectWithSize:constrainedSizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:attributescontext:nil];CGFloat textHeight = CGRectGetHeight(textRect);if (textHeight > 100) {cell.foldButton.hidden = NO;} else {cell.foldButton.hidden = YES;}

要实现评论区的展开全文和收起,需要先实现评论区文本的自适应高度,接着我用数组来记录每个按钮的状态,如果为展开状态则为1,如果为收起状态则为0。通过数组中按钮的状态为按钮的selected属性做出选择并改变cell的高度。当我点击按钮时就改变该按钮在数组中的相应值。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {if (indexPath.section == 0 && self.longComments != 0) {NSString* longStr = [self.discussModel.longCommentsArray[indexPath.row] content];NSString* longReplyStr = [self.discussModel.longCommentsArray[indexPath.row] reply_to][@"content"];CGSize constrainedSize = CGSizeMake(WIDTH - 70, CGFLOAT_MAX); // labelWidth为UILabel的宽度,高度设置为无限大UIFont *font = [UIFont systemFontOfSize:18.0];NSDictionary *attributes = @{NSFontAttributeName: font}; // label为要计算高度的UILabel控件CGRect textRect = [longStr boundingRectWithSize:constrainedSizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:attributescontext:nil];CGFloat textHeight = CGRectGetHeight(textRect);CGSize constrainedSize02 = CGSizeMake(WIDTH - 70, CGFLOAT_MAX); // labelWidth为UILabel的宽度,高度设置为无限大UIFont *font02 = [UIFont systemFontOfSize:16.0];NSDictionary *attributes02 = @{NSFontAttributeName: font02}; // label为要计算高度的UILabel控件CGRect textRect02 = [longReplyStr boundingRectWithSize:constrainedSize02options:NSStringDrawingUsesLineFragmentOriginattributes:attributes02context:nil];CGFloat textHeight02 = CGRectGetHeight(textRect02);NSLog(@"长评论高度为:%f", textHeight);if ([self.discussModel.longButtonSelectArray[indexPath.row] isEqualToString:@"1"]) {return textHeight + textHeight02 + 180;}return textHeight + 180;} else {NSString* shortStr = [self.discussModel.shortCommentsArray[indexPath.row] content];NSString* shortReplyStr = [self.discussModel.shortCommentsArray[indexPath.row] reply_to][@"content"];CGSize constrainedSize = CGSizeMake(WIDTH - 70, CGFLOAT_MAX); // labelWidth为UILabel的宽度,高度设置为无限大UIFont *font = [UIFont systemFontOfSize:18.0];NSDictionary *attributes = @{NSFontAttributeName: font}; // label为要计算高度的UILabel控件CGRect textRect = [shortStr boundingRectWithSize:constrainedSizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:attributescontext:nil];CGFloat textHeight = CGRectGetHeight(textRect);CGSize constrainedSize02 = CGSizeMake(WIDTH - 70, CGFLOAT_MAX); // labelWidth为UILabel的宽度,高度设置为无限大UIFont *font02 = [UIFont systemFontOfSize:16.0];NSDictionary *attributes02 = @{NSFontAttributeName: font02}; // label为要计算高度的UILabel控件CGRect textRect02 = [shortReplyStr boundingRectWithSize:constrainedSize02options:NSStringDrawingUsesLineFragmentOriginattributes:attributes02context:nil];CGFloat textHeight02 = CGRectGetHeight(textRect02);NSLog(@"段评论高度为:%f", textHeight);if ([self.discussModel.shortButtonSelectArray[indexPath.row] isEqualToString:@"1"]) {return textHeight + textHeight02 + 180;}return textHeight + 180;}  
}- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && self.longComments != 0) {if (indexPath.row == 0) {cell.commentsNumLabel.text = [NSString stringWithFormat:@"%ld条长评", self.longComments];}cell.foldButton.tag = indexPath.row * 2 + 1;if ([self.discussModel.longButtonSelectArray[indexPath.row] isEqualToString:@"1"]) {cell.foldButton.selected = YES;cell.replyLabel.numberOfLines = 0;} else {cell.foldButton.selected = NO;cell.replyLabel.numberOfLines = 2;}
}else {cell.foldButton.tag = indexPath.row * 2;if ([self.discussModel.shortButtonSelectArray[indexPath.row] isEqualToString:@"1"]) {cell.foldButton.selected = YES;cell.replyLabel.numberOfLines = 0;} else {cell.foldButton.selected = NO;cell.replyLabel.numberOfLines = 2;}
- (void)pressFold:(UIButton*)button {DiscussCustomCell* cell = (DiscussCustomCell*)[[button superview] superview];if ([self.discussModel.longButtonSelectArray[(button.tag - 1) / 2] isEqualToString:@"1"]) {[self.discussModel.longButtonSelectArray replaceObjectAtIndex:((button.tag - 1) / 2) withObject:@"0"];[self.discussView.tableview reloadData];} else {[self.discussModel.longButtonSelectArray replaceObjectAtIndex:((button.tag - 1) / 2) withObject:@"1"];[self.discussView.tableview reloadData];}if ([self.discussModel.shortButtonSelectArray[button.tag / 2] isEqualToString:@"1"]) {[self.discussModel.shortButtonSelectArray replaceObjectAtIndex:(button.tag / 2) withObject:@"0"];[self.discussView.tableview reloadData];} else {[self.discussModel.shortButtonSelectArray replaceObjectAtIndex:(button.tag / 2) withObject:@"1"];[self.discussView.tableview reloadData];}
}

请添加图片描述

请添加图片描述

二、FMDB库实现本地持久化

FMDB是iOS平台的SQLite数据库框架,以OC的方式封装了SQLite的C语言API。

FMDB常用类:

FMDatabase:一个FMDatabase对象就代表一个单独的SQLite数据库用来执行SQL语句。
FMResultSet:使用FMDatabase执行查询后的结果集。
FMDatabaseQueue:用于在多线程中执行多个查询或更新,它是线程安全的。

FMDB的简单使用:

要使用FMDB库首先需要通过CocoaPods来安装这个第三方库

pod 'FMDB'

安装完成之后就可以进行使用了。

创建数据库

//获取数据库文件的路径NSString* doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];NSString *fileName = [doc stringByAppendingPathComponent:@"collectionData.sqlite"];//获得数据库self.collectionDatabase = [FMDatabase databaseWithPath:fileName];//打开数据库if ([self.collectionDatabase open]) {BOOL result = [self.collectionDatabase executeUpdate:@"CREATE TABLE IF NOT EXISTS collectionData (mainLabel text NOT NULL, nameLabel text NOT NULL, imageURL text NOT NULL, networkURL text NOT NULL, dateLabel text NOT NULL, nowLocation text NOT NULL, goodState text NOT NULL, collectionState text NOT NULL, id text NOT NULL);"];if (result) {NSLog(@"创表成功");} else {NSLog(@"创表失败");}}

数据库增加数据

//插入数据
- (void)insertData {if ([self.collectionDatabase open]) {NSString *string = @"GenShen";BOOL result = [self.collectionDatabase executeUpdate:@"INSERT INTO collectionData (mainLabel, nameLabel, imageURL, networkURL, dateLabel, nowLocation, goodState, collectionState, id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);", string, string, string, string, string, string, string, string, string];if (!result) {NSLog(@"增加数据失败");}else{NSLog(@"增加数据成功");}[self.collectionDatabase close];}
}

数据库修改数据

//修改数据
- (void)updateData {if ([self.collectionDatabase open]) {NSString* sql = @"UPDATE collectionData SET id = ? WHERE nameLabel = ?";BOOL result = [self.collectionDatabase executeUpdate:sql, @"114514",@"GenShen"];if (!result) {NSLog(@"数据修改失败");} else {NSLog(@"数据修改成功");}[self.collectionDatabase close];}
}

数据库删除数据

//删除数据
- (void)deleteData {if ([self.collectionDatabase open]) {NSString* sql = @"delete from collectionData WHERE collectionState = ?";BOOL result = [self.collectionDatabase executeUpdate:sql, @"爱玩原神"];if (!result) {NSLog(@"数据删除失败");} else {NSLog(@"数据删除成功");}[self.collectionDatabase close];}
}

数据库查询数据

//查询数据
- (void)queryData {if ([self.collectionDatabase open]) {FMResultSet* resultSet = [self.collectionDatabase executeQuery:@"SELECT * FROM collectionData"];while ([resultSet next]) {NSString *mainLabel = [resultSet stringForColumn:@"mainLabel"];NSLog(@"mainLabel = %@",mainLabel);NSString *nameLabel = [resultSet stringForColumn:@"nameLabel"];NSLog(@"nameLabel = %@",nameLabel);NSString *imageURL = [resultSet stringForColumn:@"imageURL"];NSLog(@"imageURL = %@",imageURL);NSString *networkURL = [resultSet stringForColumn:@"networkURL"];NSLog(@"networkURL = %@",networkURL);NSString *dateLabel = [resultSet stringForColumn:@"dateLabel"];NSLog(@"dateLabel = %@",dateLabel);NSString *nowLocation = [resultSet stringForColumn:@"nowLocation"];NSLog(@"nowLocation = %@",nowLocation);NSString *goodState = [resultSet stringForColumn:@"goodState"];NSLog(@"goodState = %@",goodState);NSString *collectionState = [resultSet stringForColumn:@"collectionState"];NSLog(@"collectionState = %@",collectionState);NSString *id = [resultSet stringForColumn:@"id"];NSLog(@"id = %@",id);}[self.collectionDatabase close];}
}

三、点赞和收藏的持久化

要实现点赞和收藏的持久化就需要用到前面所提到的FMDB库进行操作。在需要用到数据库的部分进行数据库的创建和一些基本操作例如增删改查。以收藏持久化为例子,当点击点赞收藏按钮的时候,进入到数据库查询函数进行查询,如果找到就将该数据进行删除然后将按钮状态设置为未选中状态。如果没有找到该数据就进行添加然后将按钮状态设置为选中状态

- (void)pressCollect:(UIButton*)button {NSString* collectionIdStr = [NSString stringWithFormat:@"%ld", self.idStr];int flag = [self queryCollectionData];if (flag == 1) {self.mainWebView.collectButton.selected = NO;[self deleteCollectionData:collectionIdStr];} else {self.mainWebView.collectButton.selected = YES;[self insertCollectionData:self.mainLabel andUrl:self.imageUrl andStr:collectionIdStr];}
}

当滑动切换页面请求新闻额外信息时也需要先进行判断当前点赞和收藏的按钮状态

[[ExtraManager sharedSingleton] ExtraGetWithData:^(GetExtraModel * _Nullable extraModel) {dispatch_async(dispatch_get_main_queue(), ^{int flag = [self queryLikesData];int collectFlag = [self queryCollectionData];self.mainWebView.discussLabel.text = [NSString stringWithFormat:@"%ld", extraModel.comments];self.mainWebView.likeLabel.text = [NSString stringWithFormat:@"%ld", extraModel.popularity];self.longComments = extraModel.long_comments;self.shortComments = extraModel.short_comments;if (flag == 1) {self.mainWebView.likeButton.selected = YES;NSInteger likesNum = [self.mainWebView.likeLabel.text integerValue];likesNum++;self.mainWebView.likeLabel.text = [NSString stringWithFormat:@"%ld", likesNum];NSString* likesIdStr = [NSString stringWithFormat:@"%ld", self.idStr];[self insertLikesData:likesIdStr];} else {self.mainWebView.likeButton.selected = NO;}if (collectFlag == 1) {self.mainWebView.collectButton.selected = YES;} else {self.mainWebView.collectButton.selected = NO;}NSLog(@"额外信息获取成功");});} andError:^(NSError * _Nullable error) {NSLog(@"额外信息获取失败");} andIdStr:self.idStr];

收藏数据库部分代码如下:

//创建
- (void)databaseInit {NSString* likesDoc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];NSLog(@"%@", likesDoc);NSString * likesFileName = [likesDoc stringByAppendingPathComponent:@"likesData.sqlite"];self.likesDatabase = [FMDatabase databaseWithPath:likesFileName];if ([self.likesDatabase open]) {BOOL result = [self.likesDatabase executeUpdate:@"CREATE TABLE IF NOT EXISTS likesData (id text NOT NULL);"];if (result) {NSLog(@"创表成功");} else {NSLog(@"创表失败");}}NSString* collectionDoc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];NSLog(@"%@", collectionDoc);NSString * collectionFileName = [collectionDoc stringByAppendingPathComponent:@"collectionData02.sqlite"];self.collectionDatabase = [FMDatabase databaseWithPath:collectionFileName];if ([self.collectionDatabase open]) {BOOL result  = [self.collectionDatabase executeUpdate:@"CREATE TABLE IF NOT EXISTS collectionData (mainLabel text NOT NULL, imageURL text NOT NULL, id text NOT NULL);"];if (result) {NSLog(@"创表成功");} else {NSLog(@"创表失败");}}}
//增加
- (void)insertCollectionData:(NSString *)mainLabel andUrl:(NSString *)imageURL andStr:(NSString*)string {if ([self.collectionDatabase open]) {BOOL result = [self.collectionDatabase executeUpdate:@"INSERT INTO collectionData (mainLabel, imageURL, id) VALUES (?, ?, ?);", mainLabel, imageURL,string];if (!result) {NSLog(@"增加收藏数据失败");}else{NSLog(@"增加收藏数据成功");}}[self.collectionDatabase close];
}
//删除
- (void)deleteCollectionData:(NSString*)string {if ([self.collectionDatabase open]) {NSString *sql = @"delete from collectionData WHERE id = ?";BOOL result = [self.collectionDatabase executeUpdate:sql, string];if (!result) {NSLog(@"删除收藏数据失败");}else{NSLog(@"删除收藏数据成功");}}[self.collectionDatabase close];
}//查询
- (int)queryCollectionData {if ([self.collectionDatabase open]) {FMResultSet* collectionResultSet = [self.collectionDatabase executeQuery:@"SELECT * FROM collectionData"];int count = 0;while ([collectionResultSet next]) {NSString *sqlIdStr = [NSString stringWithFormat:@"%@", [collectionResultSet objectForColumn:@"id"]];NSInteger sqlId = [sqlIdStr integerValue];NSLog(@"第 %d 个收藏数据库数据:%ld", count++ ,sqlId);if (self.idStr == sqlId) {[self.collectionDatabase close];return 1;}}}[self.collectionDatabase close];return 0;
}

请添加图片描述

请添加图片描述


文章转载自:
http://med.zLrk.cn
http://titillate.zLrk.cn
http://subfebrile.zLrk.cn
http://cinder.zLrk.cn
http://carrollese.zLrk.cn
http://naima.zLrk.cn
http://tackey.zLrk.cn
http://hylozoism.zLrk.cn
http://albata.zLrk.cn
http://aerobiology.zLrk.cn
http://subconical.zLrk.cn
http://you.zLrk.cn
http://pseudonymous.zLrk.cn
http://exophthalmic.zLrk.cn
http://revealing.zLrk.cn
http://caretaker.zLrk.cn
http://syngas.zLrk.cn
http://renovation.zLrk.cn
http://trendily.zLrk.cn
http://crotchety.zLrk.cn
http://phonemics.zLrk.cn
http://queenless.zLrk.cn
http://overbid.zLrk.cn
http://leaderless.zLrk.cn
http://eaprom.zLrk.cn
http://assessor.zLrk.cn
http://immodest.zLrk.cn
http://dislikeable.zLrk.cn
http://zairean.zLrk.cn
http://bason.zLrk.cn
http://cystoma.zLrk.cn
http://patrolwoman.zLrk.cn
http://versal.zLrk.cn
http://interlocal.zLrk.cn
http://angular.zLrk.cn
http://aecidium.zLrk.cn
http://cosmologist.zLrk.cn
http://whim.zLrk.cn
http://nightviewer.zLrk.cn
http://acknowiedged.zLrk.cn
http://embolize.zLrk.cn
http://bulgur.zLrk.cn
http://slapdab.zLrk.cn
http://syllabogram.zLrk.cn
http://allot.zLrk.cn
http://subscription.zLrk.cn
http://nonsense.zLrk.cn
http://capsulate.zLrk.cn
http://tamableness.zLrk.cn
http://dextrocardia.zLrk.cn
http://hyperparathyroidism.zLrk.cn
http://cumulonimbus.zLrk.cn
http://peddle.zLrk.cn
http://publisher.zLrk.cn
http://saddhu.zLrk.cn
http://paceway.zLrk.cn
http://dissector.zLrk.cn
http://scratchboard.zLrk.cn
http://peridiole.zLrk.cn
http://inequitable.zLrk.cn
http://hornblende.zLrk.cn
http://moderato.zLrk.cn
http://radiomimetic.zLrk.cn
http://reflorescent.zLrk.cn
http://manwise.zLrk.cn
http://intermediary.zLrk.cn
http://middlemost.zLrk.cn
http://hedonistic.zLrk.cn
http://subcellular.zLrk.cn
http://implead.zLrk.cn
http://longton.zLrk.cn
http://gabar.zLrk.cn
http://teacup.zLrk.cn
http://haulm.zLrk.cn
http://gamut.zLrk.cn
http://desired.zLrk.cn
http://actinouranium.zLrk.cn
http://undemonstrative.zLrk.cn
http://franquista.zLrk.cn
http://wastery.zLrk.cn
http://wolfling.zLrk.cn
http://demonian.zLrk.cn
http://inwrap.zLrk.cn
http://paresthesia.zLrk.cn
http://supermart.zLrk.cn
http://evagination.zLrk.cn
http://cacographer.zLrk.cn
http://cssr.zLrk.cn
http://wiser.zLrk.cn
http://pectin.zLrk.cn
http://warren.zLrk.cn
http://profound.zLrk.cn
http://substantialist.zLrk.cn
http://capitulum.zLrk.cn
http://recommendation.zLrk.cn
http://alkali.zLrk.cn
http://infrasonic.zLrk.cn
http://braaivleis.zLrk.cn
http://tablier.zLrk.cn
http://paroicous.zLrk.cn
http://www.dt0577.cn/news/112075.html

相关文章:

  • 网络营销外包有限公司班级优化大师官网下载
  • 公司装修合同模板优化大师百科
  • c 可以用来做网站吗营销推广案例
  • 做网站在哪里申请查数据的网站有哪些
  • 能源网站开发电商网站建设公司哪家好
  • 怎样做违法网站小说引流推广
  • 在dw里如何做网站设计公司排名
  • 珠海网络营销外包收费情况外贸网站推广seo
  • 个人性质网站名称seo站长平台
  • 怎么做网页 网站制作google搜索关键词热度
  • 有网站做点什么好湖北网络推广有限公司
  • 珠海网站建设网络公司seo模板建站
  • 中山有网站建设公司吗网络推广的方式和途径有哪些
  • 我的世界搞头怎么做的视频网站网站维护的主要内容
  • 小企业官方网站制作品牌营销策略四种类型
  • 法律推广网站成都网站建设企业
  • 厦门旅游网站建设百度点击器下载
  • app定制开发网站制作网站关键词优化排名外包
  • 网红营销定义官方正版清理优化工具
  • 懂做游戏钓鱼网站的湖南网站推广公司
  • 武汉光谷医院应用商店aso优化
  • 网站加密传输怎么做营销型网站建设的步骤流程是什么
  • 网站开发外包费用会计科目厦门seo排名收费
  • 公司做两个网站有影响吗百度快速提交入口
  • 网站中的实名身份证验证怎么做网站查询ip
  • 设计创意广告衡阳seo
  • centos nginx wordpress上海企业seo
  • xunsearch做搜索网站seo优化收费
  • 做网站公司长沙哪家好网站推广宣传语
  • 做澳洲ets上什么网站seo数据优化