I tried to implement a search bar with Parse from a project I found on Google but I have a problem.
The two lines where it says //my problem
is causing the app to crash
if (self.canSearch == 0) {
//my problem query = [PFQuery queryWithClassName:self.parseClassName];
} else {
//my problem query = [PFQuery queryWithClassName:self.parseClassName];
}
in the
-(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;
}
I'm not sure what's wrong because it works in the project I am working for.
This is what it says in the console when the app crashes
libc++abi.dylib: terminating with uncaught exception of type NSException
Those lines you've identified are almost certainly not the problem. Kind of a magic trick here: NSLog(@"%@", _searchedBar);
will probably reveal that _searchedBar
is undefined, therefore .text
, therefore the parameter to whereKey
which causes the crash.
Also note that:
if (anything) {
something
} else {
something
}
Can be stated more concisely as:
something
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.