Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我的解析查询直到应用程序的其余部分完成后才完成,我如何阻止这种情况发生?_Ios_Objective C_Parse Platform_Objective C Blocks_Pfquery - Fatal编程技术网

Ios 我的解析查询直到应用程序的其余部分完成后才完成,我如何阻止这种情况发生?

Ios 我的解析查询直到应用程序的其余部分完成后才完成,我如何阻止这种情况发生?,ios,objective-c,parse-platform,objective-c-blocks,pfquery,Ios,Objective C,Parse Platform,Objective C Blocks,Pfquery,下面是解析查询,我试图在集合视图中显示类别,但是numberofitemsinssection方法在getCategories有时间从解析中提取信息之前运行numberOfItemsInSection使用getCategories\u anArrayOfCategories返回集合视图中的类别数 -(void)getCategories{ [super viewWillAppear:animated]; //calls retrieve messages method below

下面是解析查询,我试图在集合视图中显示类别,但是
numberofitemsinssection
方法在
getCategories
有时间从解析中提取信息之前运行
numberOfItemsInSection
使用
getCategories\u anArrayOfCategories
返回集合视图中的类别数

-(void)getCategories{
    [super viewWillAppear:animated];   //calls retrieve messages method below

    //get Categories where the class name is Categories
    PFQuery *query = [PFQuery queryWithClassName:@"Categories"];
    //- (void)selectKeys:(NSArray *)keys
    [query selectKeys:@[@"CName"]];
    //[query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
    [query orderByAscending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }

        else {
            _anArrayOfCategories = [[NSArray alloc] initWithArray:objects];
            NSLog(@"Test 1: Retrieved %lu Categories", (unsigned long)[_anArrayOfCategories count]);

        }
    }];

}

有什么建议吗?

在查询完成后更新表,或者在以前的控制器上进行查询,并在查询完成后推送到该控制器。请记住,这些都是UI操作,需要在主线程上完成

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }

    else {
        _anArrayOfCategories = [[NSArray alloc] initWithArray:objects];
        NSLog(@"Test 1: Retrieved %lu Categories", (unsigned long)[_anArrayOfCategories count]);
        dispatch_async(dispatch_get_main_queue(), ^{ // UI operations on the main thread
            [self.tableView reloadData];
        });

    }
}];


编辑:只是为了确保,由于您的帖子不清楚,您不想从
numberofrowsinssection
调用此方法。将其放入
viewDidLoad
或类似的程序中,然后让
numberOfRowsInSection
使用
\u anArrayOfCategories
对象。

在设置
\u arrayOfCategories
后添加对
[self.tableView reloadData]
的调用。确保调用是在主线程上进行的。嘿,非常感谢,我通过编写_anArrayOfCategories=[[NSArray alloc]initWithArray:objects]实现了调用;NSLog(@“测试1:检索到%lu个类别”,(无符号长)[[u anArrayOfCategories count]);NSLog(@“%@”,无误分类)//请记住,这些都是UI操作,需要在主线程上完成。dispatch_async(dispatch_get_main_queue(),^{[self.collectionView reloadData];这一切都是在集合视图控制器内完成的。非常感谢