简体   繁体   中英

PFUser Query - Warning: Long-running operation is being executed on main thread - iOS

I am currently attempting to populate a table from an array of usernames.

In order to retrieve the usernames, I use a PFQuery, as explained in the parse documentation:

PFQuery *query = [PFUser query];
NSArray *users = [query findObjects];

This code technically works. However, I get this warning:

Warning: A long-running operation is being executed on the main thread.

I have tried using findObjectsInBackgroundWithBloc in order to retrieve the list of usernames. However, no data is retrieved. My table is empty.

The Parse documentation explains that querying users is a separate concept, different from querying normal objects, hence my code above. This code is taken straight from the Parse documentation.

Could anyone point me in the right direction?

Thanks, Miles

Your query is taking too much time to return data that's why you are getting this warning

You can use findObjectsInBackgroundWithBlock: like this.

PFQuery *query = [PFUser query];
NSMutableArray *users;
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
    users = [[NSMutableArray alloc]initWithArray:objects];
    [tableView reloadData];
}
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM