Bmob 之 列表查询

  查询列表,返回前20个数据:

//创建BmobQuery实例,指定对应要操作的数据表名称
    BmobQuery *query = [BmobQuery queryWithClassName:className];
    //按updatedAt进行降序排列
    [query orderByDescending:@"updatedAt"];
    //返回最多20个结果
    query.limit = 20;
    //执行查询
    [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        //处理查询结果
        for (BmobObject *obj in array) {
            News *info    = [[News alloc] init];
            if ([obj objectForKey:@"title"]) {
                info.title    = [obj objectForKey:@"title"];
            }
            if ([obj objectForKey:@"describe"]) {
                info.content  = [obj objectForKey:@"describe"];
            }
            if ([obj objectForKey:@"phone"]) {
                info.phoneNum = [obj objectForKey:@"phone"];
            }
            info.time     = [_dateFormatter stringFromDate:obj.updatedAt];
            [_infoMutableArray addObject:info];
        }

        [_tableView reloadData];
    }];

 

posted on 2015-12-09 12:32  大木哥  阅读(1219)  评论(0编辑  收藏  举报

导航