[iOS开发]知乎日报第三周总结

实现的:

1.收藏界面:
[iOS开发]知乎日报第三周总结
2.滑动取消收藏
[iOS开发]知乎日报第三周总结

3.评论界面[iOS开发]知乎日报第三周总结

遇到的问题:

  1. Masonry写在layoutSubViews里失效。好像是需要手动调用。
  2. 数据库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进行进一步的学习。

上一篇:Ant design3表单一行多个组件并一齐校验


下一篇:Ant Design of Vue中table的列表中显示图片