我正在編寫一個應用程序來顯示來自門戶的一些消息。該消息使用來自Internet的JSON文件獲取,然後使用CoreData模型存儲到NSMutableArray中。很明顯,用戶不能從互聯網上的JSON文件中刪除新聞,但他可以在本地隱藏它們。這些問題來到這裏,在這裏我有以下代碼:NSMutableArray removeObjectAtIndex:拋出無效參數異常
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
if(!moc){
moc = [[NewsFetcher sharedInstance] managedObjectContext];
}
[[dataSet objectAtIndex:indexPath.row] setEliminata:[NSNumber numberWithBool:YES]];
NSError *error;
if(![moc save:&error]){
NSLog(@"C'è stato un errore!");
}
[dataSet removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
行:
[dataSet removeObjectAtIndex:indexPath.row];
原因我的應用與以下錯誤崩潰:
2010-07-12 19:08:16.021 ProvaVideo[284:207] * -[_PFArray removeObjectAtIndex:]: unrecognized selector sent to instance 0x451c820 2010-07-12 19:08:16.022 ProvaVideo[284:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_PFArray removeObjectAtIndex:]: unrecognized selector sent to instance 0x451c820'
我試圖理解爲什麼它不起作用,但我不能。 如果我重新啓動應用程序,則新的程序在邏輯上被正確取消。 有什麼建議?提前致謝。
接口:
@interface ListOfVideo : UITableViewController <NSFetchedResultsControllerDelegate> {
NSMutableArray *dataSet;
}
@property (nonatomic, retain) NSMutableArray *dataSet;
// In the .m file:
@synthesize dataSet;
初始化在viewDidLoad
:
dataSet = (NSMutableArray *) [[NewsFetcher sharedInstance]
fetchManagedObjectsForEntity:@"News"
withPredicate:predicate
withDescriptor:@"Titolo"];
[dataSet retain];
updateDatabase
...這是從網上新的新聞檢查的時候,我將它們添加在MutableArray:
[dataSet addObject:theNews];
你確定數據集是一個NSMutableArray嗎?如果它不響應removeObjectAtIndex:它可能只是一個NSArray。 – 2010-07-12 17:47:24
如果它不響應該選擇器,它不是'NSMutableArray'。您可能無法正確創建它或錯誤地使用['copy'屬性](http://stackoverflow.com/questions/3220120/nsmutablearray-addobject-nsarrayi-addobject-unrecognized-selector-sent-to/3220137#3220137)。如果您懷疑嘗試使用'-isKindOfClass:'進行測試。 – 2010-07-12 17:57:52
umble,它不是一個NSMutableArray,但是:@interface ListOfVideo:UITableViewController {NSMutableArray * dataSet; } @property(nonatomic,retain)NSMutableArray * dataSet; ... //在.m文件中@synthesize dataSet; –
IssamTP
2010-07-12 19:44:25