2011-09-21 5 views
0

나는 다음과 같은 오류가 발생하고 삭제를 가져올 수 없습니다 :코어 데이터 테이블보기 행

Unresolved error (null), (null) 

이가 관련이있을 수 있는지 어떤 아이디어 - 나는에서 항목을 삭제하려면 사용자에게 슬쩍 옵션을 허용하는 것을 시도하고있다 코어 데이터는 ... 데이터를 표시 &을 추가하면 작동 - 그러나 삭제 오류가 표시됩니다 ...

@implementation List 

@synthesize eventsArray; 
@synthesize managedObjectContext, fetchedResultsController, List; 

... 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    if (managedObjectContext == nil) 
    { 
     managedObjectContext = [(ApplicationAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
    } 


    UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editAction)]; 
    self.navigationItem.leftBarButtonItem = editButton; 

    [editButton release]; 

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target: self action:@selector(addAction)]; 
    self.navigationItem.rightBarButtonItem = addButton; 

    [addButton release]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    self.fetchedResultsController.delegate = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    List = [[NSMutableArray alloc] init]; 

    NSError *error; 
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Items" inManagedObjectContext:managedObjectContext]; 
    [fetchRequest setEntity:entity]; 
    NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; 

    for (NSManagedObject *info in fetchedObjects) 
    { 
     [List insertObject:[info valueForKey:@"Name"] atIndex:0]; 
    } 
    [fetchRequest release]; 
    [self.tableView reloadData]; 
} 

... 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [List count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Get and display the values for the keys; the key is the attribute name from the entity 
    cell.textLabel.text = [List objectAtIndex:indexPath.row]; 

    // Add a standard disclosure for drill-down navigation 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 

     NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; 
     [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 

     // Save the context. 
     NSError *error = nil; 
     if (![context save:&error]) 
     { 
      /* 
      Replace this implementation with code to handle the error appropriately. 

      abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. 
      */ 
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
      abort(); 
     } } 
} 


- (void)dealloc 
{ 
    [fetchedResultsController release]; 
    [List release]; 
    [super dealloc]; 
} 

@end 
+0

응용 프로그램에서 여러 스레드를 사용하고 있습니까? 다른 스레드 나 다른 것과 같은 컨텍스트를 사용하는 것과 같은? – HeikoG

+0

@HeikoG - 나는 그렇게 생각하지 않는다. ... –

답변

0

을 첫째로, 당신이 '목록'같은 뷰 컨트롤러 구현의 이름이 아니라라는 이름의이 바르 것 같다 명부. @implementation 선언 다음의 이름이어야하므로보기 컨트롤러 클래스의 이름을 확인하십시오.

또한 NSArray의 이름이 List이면 일반적인 코딩 규칙은 ivars가 소문자로 시작하도록 유지하는 것입니다. 대문자와 소문자로 된 클래스 이름을 소문자로 유지하면 미래에 혼동을 피할 수 있습니다.

+0

미안 - 목록은 실제로 응용 프로그램에서 "목록"이라고 실제로 부르지 않는다. - 그것은 내가 개발하고있는 응용 프로그램 이름 다음에 실제로 명명되었다. - 그러나 기밀성 때문에 이름을 바꾸어야했다. –