0

HI 코어 데이터에서 레코드를 가져올 때 HI 친구가 null을 표시합니다. 나는 문제가 뭔지 모르겠다. 어떤 신체가 내 문제를 해결하면 대단히 기쁘다. 내 코드가있다.코어 데이터에서 레코드를 가져 오는 동안 null 값을 반환합니다.

참고 : 나는 'dbmanager'

dbmanager.m 

- (NSArray *)fetchAllAds { 
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Ad" 
inManagedObjectContext:dbManager.managedObjectContext]]; 
NSError *error = nil; 
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; 
return results; 
} 

- (Ad*)addToFavourite:(NSNumber*)adId text:(NSString*)text type:(LinkupType)type { 

Ad *item = (Ad*)[NSEntityDescription insertNewObjectForEntityForName:@"Ad" 
inManagedObjectContext:self.managedObjectContext]; 
item.adId = adId; 
item.data =text; 
item.state = [NSNumber numberWithInt:type]; 
[self save]; 
return item; 
} 

- (void)save { 
NSError *error = nil; 
if (![[self managedObjectContext] save:&error]) { 
    // Update to handle the error appropriately. 
    NSLog(@"Unresolved error7 %@, %@", error, [error userInfo]); 
    exit(-1); // Fail 
} 
} 

MYviewcontroller.m 

- (void)viewDidLoad 
{ 
self.fetchedRecordsArray = [[DBManager instance]fetchAllAds]; 
[[DBManager instance]managedObjectContext]; 
[self.shoppingtbl reloadData]; 
//NSLog(@"the fetched data is %@",[[DBManager instance]fetchAllAds]); 
[super viewDidLoad]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return [self.fetchedRecordsArray count]; 

} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath 
*)indexPath 
{ 
static NSString *CellIdentifier = @"ShoppingCart"; 
ShoppingCart *cell = (ShoppingCart*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                    forIndexPath:indexPath]; 
ad=[self.fetchedRecordsArray objectAtIndex:indexPath.row]; 
cell.addesc.text =[NSString stringWithFormat:@"%@",ad.data]; 
cell.adId.text=[NSString stringWithFormat:@"%lu", (long)[ad.adId integerValue]]; 
cell.adstatus.text=[NSString stringWithFormat:@"%@",ad.state]; 
return cell; 

}라는 별도의 파일에 모든 핵심 데이터 기능을 반환

내가 그것을 nslog에서 확인 내 problem.when를 해결하기 위해 시도하십시오는 다음과 같이 보여줍니다

 "<Ad: 0x9751570> (entity: Ad; id: 0x974c6b0 <x-coredata://B3AA111F-8307-4A16-B898-403A804DFDFB/Ad/p56> ; data: <fault>)", 
"<Ad: 0x974e370> (entity: Ad; id: 0x9751af0 <x-coredata://B3AA111F-8307-4A16-B898-403A804DFDFB/Ad/p57> ; data: <fault>)" 

note: status section is showing properly! 
+0

위의 NSLog는 두 개의 개체가 있음을 보여줍니다. 이러한 개체의 속성을 기록하면 표시되는 내용은 무엇입니까? – pbasdf

답변

0

fetchedRecordsArray 배열을 별도의 반입으로 사용하는 대신 NSFetchedResultsController를 사용하십시오. ManagedObjects를 코드를 통해 유지하는 것은 스레드로부터 안전하지 않습니다.

+0

이 같은 새 관리 개체 요청을 만들 때 - NSManagedObject * record = [self.fetchedResultsController objectAtIndexPath : indexPath]; – user3354840

+0

테이블 뷰 셀을 구현하는 방법은 무엇입니까? – user3354840

+0

이 링크를 사용하십시오 : http://stackoverflow.com/questions/18361651/ios-uitableview-sections-with-fetchedresultscontroller-confusion – kabarga