0
其工作:謂詞不工作時,我試圖通過串
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dateSave ==[c] %@",[[UtilityClass dateComponentsFromDate:[NSDate date]] valueForKey:@"date"]];
但我需要獲取:
str_predicate=[NSString stringWithFormat:@"%@ AND hourSave == %d",str_predicate, [[[[self.dict_ChallengesAccepted valueForKey:@"ChallengesAccepted"]objectAtIndex:indexPath.row]valueForKey:@"accept_time"] intValue]+diff_Hour];
str_predicate=[NSString stringWithFormat:@"%@ dateSave == %@",[str_predicate stringByReplacingOccurrencesOfString:@"1 AND "
withString:@""],[[UtilityClass dateComponentsFromDate:[NSDate date]] valueForKey:@"date"]];
[NSPredicate predicateWithFormat:str_predicate]
謂語登錄= dateSave == [C]「2014年9月26日「AND hourSave ==並[c] 」18「 AND hourSave hourSave ==並[c] 」19「
如果我只通過dateSave ==並[c] 」2014年9月26日「,那麼它的返回數據
但是當我嘗試通過dateSave == [c]「2014-09-26」AND hourSave == [c]「18」AND hourSave hourSave == [c]「19」return 0
但在我的數據庫有數據18 &19小時插槽
我能解決這個問題:
我更新的代碼是:
int hourDiff=[[[NSDictionary dictionaryWithDictionary:[UtilityClass dateComponentsFromDate: [NSDate date]]]valueForKey:@"hour"] intValue]-[[[[self.dict_ChallengesAccepted valueForKey:@"ChallengesAccepted"]objectAtIndex:indexPath.row]valueForKey:@"accept_time"]intValue];
for (int diff_Hour=0; diff_Hour<=hourDiff; diff_Hour++) {
[predicatesArray addObject:[NSPredicate predicateWithFormat:@"hourSave ==[c] %d", [[[[self.dict_ChallengesAccepted valueForKey:@"ChallengesAccepted"]objectAtIndex:indexPath.row]valueForKey:@"accept_time"] intValue]+diff_Hour]];
}
predicate=[NSCompoundPredicate orPredicateWithSubpredicates:predicatesArray];
NSArray *searchPredicatesArray = [NSArray arrayWithObjects:[NSPredicate predicateWithFormat:@"dateSave ==[c] %@",[[[self.dict_ChallengesAccepted valueForKey:@"ChallengesAccepted"]objectAtIndex:indexPath.row]valueForKey:@"accept_date"]],predicate, nil];
predicate=[NSCompoundPredicate andPredicateWithSubpredicates:searchPredicatesArray];
我能夠成功解決我的問題。以下是我更新的代碼。 – 2014-09-26 15:55:12