0
내 iOS 앱에서 JSON을 가져 와서 배열로 설정합니다. 나는 다음과 같은 방법 UITableView
결과 필터링 설정 한배열 수준의 인스턴스 카운터를 사용하는 NSPredicate 필터
links = {
"link_1" = {
clicks = 1;
ip = "10.0.0.0";
shorturl = "http://on.example.com/abc";
timestamp = "2013-10-30 05:56:51";
title = Example Website;
url = "http://example.com/page/1/path/";
};
"link_2" = {
clicks = 10;
ip = "10.0.0.0";
shorturl = "http://on.example.com/def";
timestamp = "2013-10-16 16:55:47";
title = "Fitbit Force Is the Smartest Fitness Tracker Yet [REVIEW]";
url = "http://mashable.com/2013/10/16/fitbit-force-review/";
};
:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"links.link_1.title contains[cd] %@",
searchText];
searchResults = [filterArray filteredArrayUsingPredicate:resultPredicate];
}
을 내가 , link_2
, link_3
, ...
predicateWithFormat
필터를 업데이트해야 배열은 다음과 같습니다
질문들 : 필터를 내 배열의 "레벨"과 일치 시키려면 어떻게해야합니까? r link_
은 항상 양수이지만 무한한 자릿수가 될 수 있습니까?
기본적으로 모든 양수에 대해 link_
레벨의 배열을 검색해야합니다.
'.allValues '는 어디에서 왔습니까? 당신의 답을 이해할 수 있도록 제 코드를 사용하는 예를 들어 주시겠습니까? - 감사! – adamdehaven
@adamdehaven allValues는 NSDictionary의 메서드입니다. 링크는 NSDictionary 개체이므로 모든 값을 가져 와서 필터링해야합니다. 예를 들면 나는 약간의 해답이 필요하다. 코드에서 filterArray 변수 란 무엇입니까? 인쇄 된 링크 개체와 어떤 관련이 있습니까? –
'links' 객체는 실제로는 NSArray * filterArray의 NSLog입니다. 'filterArray = [NSArray arrayWithObject : [NSJSONSerialization JSONObjectWithData : 데이터 옵션 : kNilOptions 오류 : & 오류]] ' – adamdehaven