gpt4 book ai didi

ios - 查询 PFQueryTableViewController

转载 作者:行者123 更新时间:2023-11-29 12:22:08 26 4
gpt4 key购买 nike

我正在将来自 User 类的用户数据从 Parse 加载到 PFQueryTableViewController 中。用户类代表来自 Facebook 的数据。现在,我不想将数据加载到当前登录用户的 PFQueryTable 中。允许加载所有其他用户数据。这是我的查询,但它仍然从 User 类加载所有数据。有什么建议吗?

- (PFQuery *)queryForTable
{
PFQuery *query;
//[query whereKey:@"FacebookID" notEqualTo:[[PFUser currentUser] objectForKey:@"FacebookID"]];
//[query whereKey:@"username" notEqualTo:[PFUser currentUser].username];
if (self.canSearch == 0) {
query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"objectId" notEqualTo:[PFUser currentUser].objectId];
} else {
query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"objectId" notEqualTo:[PFUser currentUser].objectId];
[query whereKey:@"username" matchesRegex:_searchbar.text];
}
[query orderByAscending:@"createdAt"];
// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
return query;
}

最佳答案

发生这种情况的原因是,您正在设置此约束 [query whereKey:@"FacebookID"notEqualTo:[[PFUser currentUser] objectForKey:@"FacebookID"]] before 正在初始化您的查询。将行移动到初始化代码下方,它将起作用。

示例更正代码:

- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"FacebookID" notEqualTo:[[PFUser currentUser] objectForKey:@"FacebookID"]];
//[query whereKey:@"FacebookID" notEqualTo:[PFUser currentUser]];
if (self.canSearch != 0) {
[query whereKey:@"username" matchesRegex:_searchbar.text];
}
[query orderByAscending:@"createdAt"];
// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
return query;
}

替代方案:

所有 Parse 类都有一个唯一的键,objectId。我建议您在查询中使用它作为约束。

- (PFQuery *)queryForTable {

PFQuery *query = [PFUser query]; // [PFUser query] is same as [PFQuery queryWithClassName@"_User"]
[query whereKey:@"objectId" notEqualTo:[PFUser currentUser].objectId];
[query whereKey:@"username" matchesRegex:[NSString stringWithFormat:@"^%@", _searchBar.text] modifiers:@"i"]; // Case insensitive search

// ...other code...

return query;
}

关于ios - 查询 PFQueryTableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30304474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com