【问题标题】:How to store the Data from Parse.com to Sqlite DataBase in iOS?如何将 Parse.com 中的数据存储到 iOS 中的 Sqlite 数据库?
【发布时间】:2014-04-22 10:53:51
【问题描述】:

我正在使用 parse.com 获取如下所示的数据。我已经使用 sqlite manager 创建了数据库。

- (IBAction)button:(id)sender {
    PFQuery *postQuery = [PFQuery queryWithClassName:@"movie"];

    //movie is the class name in the parse.com in that two columns store the data
    [postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            //Save results and update the table
            self.postArray = objects;
            NSLog(@"array....%@",self.postArray);
            //  [spinner startAnimating];
            [self.myTable reloadData];
        }
    }];
}

- (void)getTheData:(id)sender {
    //it is sqlite query class
    model=[[DataModel alloc]init];

    //here insertQuery method to send the columns class object(buk).

    [model insertInformIntoDB:buk];

    PFObject *post = [self.postArray objectAtIndex:indexPath.row];

    NSLog(@"posttttt......%@",post);

    //here parse.com column name to send the data into sqlite Columns
    buk.name=[post objectForKey:@"name"];
    buk.Hero=[post objectForKey:@"Hero"];
}

我得到这样的输出:

//这是整个电影类

array....(
    "<movie:EHx3UonJmw:(null)> {\n    Hero = Mahesh;\n    name = pokiri;\n    num = 222;\n}",
    "<movie:zekgTzIsLs:(null)> {\n    Hero = pawan;\n    name = jhoni;\n    num = 412;\n}",
    "<movie:0z3ZkI4lvB:(null)> {\n    Hero = Prabhas;\n    name = darling;\n    num = 312;\n}"
)

posttttt......<movie:EHx3UonJmw:(null)> {
    Hero = Mahesh;
    name = pokiri;
    num = 222;
}

错误:-

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSMutableString stringWithUTF8String:]: NULL cString'    

但是这里在 buk.name 和 Hero 中得到空值....

【问题讨论】:

  • NSLog(@"posttttt......%@",post); 记录了什么?
  • PFObject *post = [self.postArray objectAtIndex:indexPath.row]; //这里先从parse.com获取数据我们在发送到post后进入postArray
  • 你的问题现在变得一团糟。你有例外,你也有 nil 值?你的问题是什么异常或零值?我认为应该先例外
  • 在这里查看link 帮助你!..如果有帮助,别忘了投票!
  • 非常感谢你对我非常有用 walle84

标签: ios sqlite parse-platform objective-c-blocks


【解决方案1】:

您的问题令人困惑,但我仍然很想说明可能有什么问题, [model insertInformIntoDB:buk]; 应该在设置buk 变量属性的方法的末尾

-(void)getTheData:(id)sender{
  //it is sqlite query class
  model=[[DataModel alloc]init];

  //here insertQuery method to send the columns class object(buk).

  //inserting the buk without setting the values, so move this statement at the end
  //[model insertInformIntoDB:buk];


  PFObject *post = [self.postArray objectAtIndex:indexPath.row];

  NSLog(@"posttttt......%@",post);

  //here parse.com column name to send the data into sqlite Columns
  buk.name=[post objectForKey:@"name"];
  buk.Hero=[post objectForKey:@"Hero"];

  //save the buk
  [model insertInformIntoDB:buk];
}

【讨论】:

  • buk 是 sqlite 列类:书籍。在当前类的.h文件中导入并设置属性
猜你喜欢
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 2014-04-07
  • 2016-09-13
  • 2010-11-18
  • 1970-01-01
相关资源
最近更新 更多