5

我看过其他关于无法识别的选择器错误的帖子,但没有关于以下方法中自动生成的代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:forRowAtIndexPath:

当我滑动删除时调用它,当我点击删除按钮时,我收到以下错误:

-[Vehicle removeObjectFromGasUpsAtIndex:]:无法识别的选择器发送到实例 0x8172c60

我的 NSManagedObject 类 Vehicle 有一个名为 gasUps 的 NSOrderedSet 变量,当我想删除它时,它应该响应这条消息。或者我是这么想的。

这是崩溃的整个方法:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (editingStyle == UITableViewCellEditingStyleDelete) {
    // need to delete gas up and not vehicle
    int row = [indexPath row];

    //[self.selectedVehicle removeObjectFromGasUpsAtIndex:row];
    [self.selectedVehicle removeObjectFromGasUpsAtIndex:row];
    NSError *error = nil;
    if (![self.managedObjectContext 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. 
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
 }   
}

为什么这个选择器无法识别?

编辑:这是给乔迪的。

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

typedef enum {
    FullExtract,
    NameExtract
} kTitleExtract;

@interface Vehicle : NSManagedObject

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * year;
@property (nonatomic, retain) NSString * make;
@property (nonatomic, retain) NSNumber * mileage;
@property (nonatomic, retain) NSString * model;
@property (nonatomic, retain) NSOrderedSet *gasUps;

// added methods
- (NSString *)getTitleExtract:(kTitleExtract)titleExtract;

@end

@interface Vehicle (CoreDataGeneratedAccessors)

- (void)insertObject:(NSManagedObject *)value inGasUpsAtIndex:(NSUInteger)idx;
- (void)removeObjectFromGasUpsAtIndex:(NSUInteger)idx;
- (void)insertGasUps:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeGasUpsAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInGasUpsAtIndex:(NSUInteger)idx withObject:(NSManagedObject *)value;
- (void)replaceGasUpsAtIndexes:(NSIndexSet *)indexes withGasUps:(NSArray *)values;
- (void)addGasUpsObject:(NSManagedObject *)value;
- (void)removeGasUpsObject:(NSManagedObject *)value;
- (void)addGasUps:(NSOrderedSet *)values;
- (void)removeGasUps:(NSOrderedSet *)values;

@end

这是设置 self.selectedVehicle 的代码片段:

if (self.vehiclesArray != nil  && [self.vehiclesArray count] != 0 && self.vehicleIndex != -1) {
    // enable add buttom
    [self.navigationItem.rightBarButtonItem setEnabled:YES];
    self.selectedVehicle = [self.vehiclesArray objectAtIndex:self.vehicleIndex];
    NSLog(@"set selected vehicle");
} else {
    // disable add button
    [self.navigationItem.rightBarButtonItem setEnabled:NO];

    // set vehicle defaults to -1 and make disable add buttom
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setInteger:-1 forKey:@"vehicleIndex"];
    [defaults synchronize];
    NSLog(@"set index to -1");
}
4

1 回答 1

5

这可能与 Core Data 为有序的一对多关系自动生成的访问器中的一个已知错误有关。

rdar://10114310

Until this is addressed you need to provide your own implementation for the missing accessors.

See answers to this question

于 2012-09-12T01:36:58.490 回答