2017-03-28 22 views
0

詳細リストから複数の単語を入力してリストを検索したいと考えています。クレーム要求リストに 例えば があり、金額、リクエスタ名、リクエスト名および番号などの異なるタイプのlableがある。だから私はこのラベルから何かを探して、私が正確な要求を見つけることができるようにしたい。単一検索で複数の単語を検索するNSPredicateを使用してiOSを迅速に検索

In this image i have made a sample list having type, requestor, reg no and amount. I want to search the list by typing multi words using these params.

+1

私達にあなたの試してみましたを表示しますか? –

+0

'filter'を使うのは' NSPredicate'よりも簡単です – Tj3n

+0

実際に私はこれに従っています:(http://www.theappguruz.com/blog/tableview-search-in-swift)これは単一の検索のためのものです。しかし、マルチワードを見つけることができません。 –

答えて

0
var predicateList = [NSPredicate]() 

let words = filterText.componentsSeparatedByString(" ") 

for word in words{ 

if count(word)==0{ 
     continue 
} 

let RequestTypeArray = NSPredicate(format: "RequestType contains[c] %@", word) 
let RequestEmployeeArray = NSPredicate(format: "RequestorEmployee contains[c] %@", word) 
let RegesterNumberArray = NSPredicate(format: "ReqNo contains[c] %@", word) 
let AmountOrDaysArray = NSPredicate(format: "AmountOrDays contains[c] %@", word) 

let orCompoundPredicate = NSCompoundPredicate(type: NSCompoundPredicateType.OrPredicateType, subpredicates: [firstNamePredicate, lastNamePredicate,departmentPredicate,jobTitlePredicate]) 

predicateList.append(orCompoundPredicate) 
} 

    request.predicate = NSCompoundPredicate(type: NSCompoundPredicateType.AndPredicateType, subpredicates: predicateList) 
+0

iは上記のコードを書く 言葉は= filterText.componentsSeparatedByString(」「)させ 私はエラーが未解決の識別子 "filtertext" の:::利用 –

+0

を取得 を続けるFUNC filterTableViewForEnterText(検索テキスト:文字列){// filterTextとして使用されるこの検索テキスト} –

+0

せた単語= filterText.componentsSeparatedByString(」「)私は を取得しています'(String) - >()'型のエラー値はメンバ 'componentsSeparatedByString' –

0

この答えである可能性があり参考になりました。..

let addresspredicate = NSPredicate(format: "address_name contains[c] %@",searchText) 
    let accnopredicate = NSPredicate(format: "acc_no contains[c] %@",searchText) 
    let propertytype = NSPredicate(format: "property_type contains[c] %@",searchText) 
    let subpropertytypoe = NSPredicate(format: "subproperty_type contains[c] %@",searchText) 

    let predicateCompound = NSCompoundPredicate.init(type: .or, subpredicates: [addresspredicate,accnopredicate,propertytype,subpropertytypoe]) 
    filteredProperty = (propertyArray as Array).filter { predicateCompound.evaluate(with: $0) }; 
    print("filteredProperty = ,\(filteredProperty)") 
関連する問題