什么自己做网站,行者seo无敌,php网站开发的第三章,西安房产信息网新学到的
本周新学习了FMDB数据库#xff0c;并对Masonry的使用有了更近一步的了解#xff0c;还了解了cell的自适应高度
FMDB数据库的介绍和使用#xff1a;iOS——FMDB的介绍与使用
cell自适应高度和Mansonry自动布局
本周写了评论区#xff0c;在写评论区的时候并对Masonry的使用有了更近一步的了解还了解了cell的自适应高度
FMDB数据库的介绍和使用iOS——FMDB的介绍与使用
cell自适应高度和Mansonry自动布局
本周写了评论区在写评论区的时候学到了cell的自适应高度。首先是要将tableView的rowHeight属性设置为UITableViewAutomaticDimension这样就可以使cell自动适应cell内容的高度。如下 self.pingLunView.tableView.rowHeight UITableViewAutomaticDimension;然后要对cell中的控件位置使用Masonry自动布局。因为这个cell自适应高度是要依靠cell中的内容的布局的相当于靠cell中内容的大小将cell撑大。因此在cell中的Masonry布局中我们只要设置控件的left、right、top、bottom即可要注意这块一定要把布局设置合理了我在写布局的时候两个控件的布局发生冲突程序虽然没崩但是一直报警告。代码实现如下 [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.contentView).offset(70);make.top.equalTo(self.contentView).offset(10);make.width.equalTo((self.contentView.bounds.size.width - 90));make.height.equalTo(30);}];[self.pingLunLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.nameLabel.mas_left);make.top.equalTo(self.nameLabel.mas_bottom).offset(10);make.right.equalTo(self.contentView.mas_right).offset(-20);make.bottom.equalTo(self.replylabel.mas_top).offset(-10);}];[self.dianZanButton mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.contentView.mas_right).offset(-60);make.top.equalTo(self.contentView.mas_bottom).offset(-30);make.right.equalTo(self.contentView.mas_right).offset(-30);make.bottom.equalTo(self.contentView.mas_bottom).offset(-30);}];[self.replylabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.pingLunLabel.mas_left);make.top.equalTo(self.pingLunLabel.mas_bottom).offset(10);make.right.equalTo(self.pingLunLabel.mas_right);make.bottom.equalTo(self.contentView.mas_bottom).offset(-50);}];使用FMDB本地存储数据
在实现本地持久化时我用到了FMDB。首先我在收藏的功能中使用了FMDB具体用法是在收藏的Model层中写了FMDB的相关方法在显示具体页面的部分有收藏按钮如果点击了收藏按钮就将当前页面的id、url、title、hint、image属性以及收藏和点赞的BOOL值使用FMDB的增加方法加入数据库反之如果取消收藏按钮就将该数据删除。然后在收藏的tableView中将FMDB中的数据放入cell中就可以完成收藏的本地持久化。 在从数据库中查找数据的方法我返回的是一个数组这个数组中存放着字典。
- (NSArray*)findDataWithChoice: (BOOL) isurl{if ([self.collectionDatabase open]) {NSMutableArray *array [[NSMutableArray alloc] init];if (isurl YES) {FMResultSet *resultSet [self.collectionDatabase executeQuery:SELECT * FROM collectionData];while ([resultSet next]) {NSString *url [resultSet stringForColumn:url];NSString *idstr [resultSet stringForColumn:id];NSDictionary *dict [NSDictionary dictionaryWithObjectsAndKeys: idstr, ID, url, url, nil];[array addObject:dict];}[self.collectionDatabase close];return array;} else {FMResultSet *resultSet [self.collectionDatabase executeQuery:SELECT * FROM collectionData];while ([resultSet next]) {NSString *titleStr [resultSet stringForColumn:title];NSString *hintStr [resultSet stringForColumn:hint];NSString *imageStr [resultSet stringForColumn:image];NSDictionary *dict [NSDictionary dictionaryWithObjectsAndKeys:titleStr, title, hintStr, hint, imageStr, image, nil];[array addObject:dict];}[self.collectionDatabase close];return array;}}return nil;
}对之前写的内容的优化修改
在一开始写评论区的时候头像的获取的图片的请求我是放在cell中的导致每当出现cell出现和消失的时候都会再次请求一遍头像因此我修改为将请求的头像放在一个数组中再赋值就可以让cell只请求一遍不会反复请求。
效果图
评论区 收藏
还有问题的地方
评论区的折叠展开评论功能因为获取label的高度还有问题因此还没有完成 收藏功能因为收藏顺序和加入数据库的顺序相反因此在左右滑动收藏的页面时有bug 点赞和收藏的状态还没有写完