[iOS开发]知乎日报第三周总结
作者:互联网
实现的:
1.收藏界面:
2.滑动取消收藏
3.评论界面
遇到的问题:
- Masonry写在layoutSubViews里失效。好像是需要手动调用。
- 数据库FMDB的使用,代码:
- (void)creatTable {
NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [documents firstObject];
_favoriteFilePath = [documentsPath stringByAppendingPathComponent:@"favourites.db"];
// NSLog(@"%@", _favoriteFilePath);
_dataBase = [FMDatabase databaseWithPath:_favoriteFilePath];
if ([_dataBase open]) {
// NSLog(@"打开成功");
NSString *createTableSql = @"create table if not exists ObjectTable(id integer primary key autoincrement,Name text)";
BOOL success=[_dataBase executeUpdate:createTableSql];
if (success) {
// NSLog(@"创建表成功");
} else {
NSLog(@"创建表失败");
}
} else {
NSLog(@"打开失败");
}
}
- (void)select//查询数据
{
NSString *selectSQL=@"select * from ObjectTable";
FMResultSet *set = [_dataBase executeQuery:selectSQL];
//需要对结果集进行遍历操作
while ([set next]) {
//获取下一条记录,如果没有下一条,返回NO;
//取数据
NSString *ID = [set stringForColumn:@"Name"];
// NSInteger num = [set intForColumn:@"id"];
[_articlePageView.favoriteIDs addObject:ID];
// NSLog(@"%@, ID=%ld", ID, num);
}
}
-(void)insert:(NSString *)ID//插入数据
{
NSString *insertSQL=@"insert into ObjectTable (Name) values (?)";
BOOL success=[_dataBase executeUpdate:insertSQL, ID];
if (success) {
// NSLog(@"插入成功");
} else {
NSLog(@"插入失败");
}
}
-(void)delete:(NSString *)ID//删除数据
{
NSString *deleteSQL=@"delete from ObjectTable where Name=? ";
BOOL success=[_dataBase executeUpdate:deleteSQL, ID];
if (success) {
// NSLog(@"删除成功");
} else {
NSLog(@"删除失败");
}
}
接下来还要对FMDB进行进一步的学习。
标签:知乎,success,dataBase,iOS,void,第三周,NSString,NSLog,ID 来源: https://blog.csdn.net/weixin_52192405/article/details/121181267