[英]Problems Implementing Search Bar with Parse
我尝试通过我在Google上找到的项目中的Parse来实现搜索栏,但遇到了问题。
表示“ //my problem
导致应用崩溃”的两行
if (self.canSearch == 0) {
//my problem query = [PFQuery queryWithClassName:self.parseClassName];
} else {
//my problem query = [PFQuery queryWithClassName:self.parseClassName];
}
在里面
-(PFQuery *)queryForTable {
PFQuery *query;
if (self.canSearch == 0) {
query = [PFQuery queryWithClassName:self.parseClassName];
} else {
query = [PFQuery queryWithClassName:self.parseClassName];
}
NSString *searchThis = [_searchedBar.text lowercaseString];
[query whereKey:@"item1" containsString:searchThis];
}
[query orderByAscending:@"item1"];
// 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;
}
我不确定发生了什么问题,因为它可以在我正在工作的项目中使用。
这是应用程序崩溃时在控制台中所说的
libc++abi.dylib: terminating with uncaught exception of type NSException
您确定的那些行几乎肯定不是问题。 这里有种魔术: NSLog(@"%@", _searchedBar);
可能会发现_searchedBar
是未定义的,因此是.text
,因此是whereKey
的参数, whereKey
导致崩溃。
另请注意:
if (anything) {
something
} else {
something
}
可以更简洁地表述为:
something
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.