我尝试使用我在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
答案 0 :(得分:0)
您确定的那些线几乎肯定不是问题。这里有一个神奇的技巧:NSLog(@"%@", _searchedBar);
可能会显示_searchedBar
未定义,因此.text
,因此导致崩溃的whereKey
参数。
另请注意:
if (anything) {
something
} else {
something
}
可以更简洁地说:
something