5
我看到關於無法識別的選擇錯誤以外的其他職位,但沒有關於在下面的方法自動生成的代碼:核心數據崩潰 - 無法識別的選擇
- (void)tableView:(UITableView *)tableView commitEditingStyle:forRowAtIndexPath:
當我滑動刪除這就是所謂的,並當我點擊刪除按鈕,我得到以下錯誤:
-[Vehicle removeObjectFromGasUpsAtIndex:]: unrecognized selector sent to instance 0x8172c60
我的NSManagedObject類,汽車,有一個NSOrderedSet變量命名gasUps當我想刪除它應該對這一消息作出迴應。或者我想。
這裏是它崩潰的整個方法:
- (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");
}
您基本上沒有提供有用的信息。只是一個錯誤,和一行代碼。基本上沒有其他的背景。我們不介意讀者。我們可以告訴你的所有內容與運行時相同:對象不識別選擇器'removeObjectFromGasUpsAtIndex'。現在,如果你想顯示定義'Vehicle'類型的代碼,以及如何設置'self.selectedVehicle',甚至可以在發送消息之前記錄對象的日誌,那麼也許你可以得到一些幫幫我。 –
[NSOrderedSet生成的訪問器中拋出的異常]的可能重複(http://stackoverflow.com/questions/7385439/exception-thrown-in-nsorderedset-generated-accessors) – jrturton