0
我有一個數據模型,看起來像這樣:核心數據獲取請求
我告訴顧客在tableview中,當用戶選擇一個客戶列表,它則顯示房間列表該客戶 - 這一切目前正常工作。
我得到的問題是當我嘗試顯示房間的詳細視圖。當用戶選擇房間時,它將顯示包含該房間所有值的視圖。 (以及應該做的)。我有這個工作在一定程度上,但如果我有兩個房間命名相同即「 - 臥室1」,爲兩個不同的客戶,然後它不顯示正確的房間數據。
這裏是我使用的代碼:
AppDelegate_Shared *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Rooms" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(Room = %@)", titleStr];
[request setPredicate:pred];
NSManagedObject *matches = nil;
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
if ([objects count] == 0)
{
NSLog(@"No matches");
} else
{
matches = [objects objectAtIndex:0];
NSLog(@"matches found");
aLbl.text = [matches valueForKey:@"DimA"];
}
[request release];
[NSFetchedResultsController deleteCacheWithName:nil];
[self.fetchedResultsController.fetchRequest setPredicate:pred];
我想發生什麼事,是詳細信息視圖顯示了基於什麼客戶已經選擇的細節。
任何幫助深表感謝......
感謝
[NSPredicate predicateWithFormat:@「(Room ==%@)AND(CustomerRelationship ==%@)」,titleStr,customerManagedObject] – zrxq
謝謝,就是這麼做的!謝幕 :-) –