"self.tableInfo"(NSMutableArray
)에 NSPredicate
을 사용하면 CheckIn
객체를 얻기 위해 다음과 같은 구조의 조건부 키 "이름"을 사용할 수 있습니다. self.tableInfo에는 SectionInfo의 배열이 있고 각 SectionInfo에는 셀 (CellInfo)이 있으며 각 셀에는 checkin 객체가 있습니다. 이것은 항상 0 카운트 저를 반환중첩 된 객체에 대한 NSPredicate 문제 IOS
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if([searchText length] != 0) {
[self filterContentForSearchText:searchText];
}
}
- (void)filterContentForSearchText:(NSString *)searchText {
NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"ANY cells.object.name contains[c] %@", searchText];
NSArray * filteredArray = [self.filteredTableInfo filteredArrayUsingPredicate:namePredicate];
self.tableInfo = [NSMutableArray arrayWithArray:@[filteredArray]];
[self.tableView reloadData];
}
:
- (void)configureView {
self.tableInfo = [NSMutableArray alloc]init];
self.filteredTableInfo = [NSMutableArray alloc]init];
NSArray *checkIns = [CheckIn MR_findAll];
SectionInfo*checkInSection = [SectionInfo section];
for (CheckIn *checkIn in checkIns) {
CellInfo *listCell = (CellInfo *)[CellInfo cell];
listCell.className = NSStringFromClass([FeedListCell class]);
listCell.height = 260;
listCell.object = checkIn;
[checkInSection.cells addObject:listCell];
}
if ([checkIns count] > 0) {
self.tableInfo = [NSMutableArray arrayWithArray:@[checkInSection]];
self.filteredTableInfo = self.tableInfo;
[self.tableView setHidden:NO];
[self.tableView reloadData];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (self.tableInfo) {
return self.tableInfo.count;
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.tableInfo && (section < self.tableInfo.count)) {
SectionInfo *sectionInfo = [self.tableInfo objectAtIndex:section];
return sectionInfo.numberOfCells;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SectionInfo *sectionInfo = self.tableInfo[indexPath.section];
CellInfo *formInfoCell = sectionInfo.cells[indexPath.row];
CheckIn *checkin = formInfoCell.object;
NSLog(@"%@", checkIn.name);
}
내가 사용하고있는 방법은 같은 것입니다. 이 문제를 해결할 더 좋은 아이디어가 있습니까?
감사합니다. NSPredicate * namePredicate = [NSPredicate predicateWithFormat : @ "모든 셀. 객체 이름에 [c] % @", searchText]가 포함되어 있습니다. NSArray * filteredSections = [self.tableInfo filteredArrayUsingPredicate : namePredicate]; 그러나 결과는 항상 빈 배열입니다. sectionInfo 객체가 필요합니다. –
검색하기 전에 self.tableInfo가 초기화되고 채워 졌는지 확신합니까? 나는 NSLog() 배열을 찾고 당신이 찾고있는 객체를 찾을 수 있는지를 확인하기 위해 단지 술어가 실패한 술어라는 것을 확신해야한다. –
예 콘솔에서 "Po self.tableInfo"를 사용하는 동안 NSLog()를 사용하여 로그를 다시 확인했습니다. NSLog (@ "self.tableInfo before predicate : % @", self.tableInfo); 술어 이전에 self.tableInfo :( "" ) NSLog (@ "filteredSections : % @", filteredSections); filteredSections :( ) NSLog (@ "filteredSections 배열 수 : % lu", (부호없는 길이) [filteredSections count]); filteredSections 배열 개수 : 0 검색 키 "a"가 내 Checkin 개체에 있음을 확신합니다. –