簡體   English   中英

使用解析實現搜索欄時出現問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM