0
我在我的應用程序中犯了一個奇怪的錯誤,並且我爲什麼這樣表現不知所措。如果實體中有多於0個對象,它將顯示正確的數量。如果實體中有0個對象,它將顯示1而不是0(即使它在另一個獲取請求中正常工作)。核心數據返回1,即使有零個對象被提取
注意:「cell.badgeString」沒什麼特別之處,它只是顯示披露指標在實體中的對象的計數。
if (cell.tag == 0)
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Uploads" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
[request setIncludesSubentities:NO];
NSArray *results = [self.managedObjectContext executeFetchRequest:request error:nil];
NSArray *resultString = [results valueForKey:@"url"];
NSString *string = [resultString description];
// I'm thinking it has something to do with this right here, maybe that is why it is displaying one instead of zero?
NSArray *count = [string componentsSeparatedByString:@","];
NSString *upload_amount = [[NSNumber numberWithInteger:count.count] stringValue];
cell.badgeString = upload_amount;
}
我不能只是做[self.managedContext countForFetchRequest],因爲我有一組存儲在覈心數據字符串的URL,我必須給他們一個第一分離得到正確的金額。
感謝您的任何幫助。