OGeek|极客世界-中国程序员成长平台

标题: ios - PFQuery同步调用有效,异步调用失败 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:09
标题: ios - PFQuery同步调用有效,异步调用失败

我是使用解析的新手,在查询我在解析类中添加的数据时遇到了一些问题。我的问题是我可以让同步调用([query findObjects])工作,但是异步调用([queryInBackground...])却失败了。

这是两个代码片段:

-(void)getAllDataFromParse{
    //simple query works
    PFQuery *query = [PFQuery queryWithClassName"wordsDB"];
    [query setLimit: 1000];
    NSArray *objects = [query findObjects];
    }
   //background query not working
   PFQuery *queryInBackground = [PFQuery queryWithClassName"wordsDB"];
   [queryInBackground findObjectsInBackgroundWithBlock:^(NSArray *objects2, NSError *error) {
       if (!error) {
           //query succeeds, do something
           }
       } else {
          // Log details of the failure
          NSLog(@"Error: %@ %@", error, [error userInfo]);
       }
  }];
}

这个方法在我的mainViewController中调用,调用在viewDidLoad函数的末尾

[self performSelectorselector(getAllDataFromParse)];

在调试时,程序到达[queryInBackground findObjectsInBackgroundWithBlock....],但在执行时,它直接跳到方法的末尾。

我看不到任何错误消息。谁能告诉我我的异步调用出了什么问题?

我已经尝试在模拟器和真实设备上运行它。



Best Answer-推荐答案


这是一个异步调用,意味着它将继续在后台运行。方法结束是完全正常的。

[queryInBackground findObjectsInBackgroundWithBlock:^(NSArray *objects2, NSError *error) {
       if (!error) {
           //query succeeds, do something
           }
       } else {
          // Log details of the failure
          NSLog(@"Error: %@ %@", error, [error userInfo]);
       }
  }];

This may also help.

关于ios - PFQuery同步调用有效,异步调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31590101/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4