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

39 篇文章 0 订阅

实现的:

1.收藏界面:
请添加图片描述
2.滑动取消收藏
请添加图片描述

3.评论界面请添加图片描述

遇到的问题:

  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进行进一步的学习。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值