【发布时间】:2017-11-09 10:05:30
【问题描述】:
我的代码如下:
- (void)didClickSave {
if([_addView.name.text isEqualToString:@""]||[_addView.time.text isEqualToString:@""]||[_addView.number.text isEqualToString:@""]||[_addView.country.text isEqualToString:@""]||[_addView.intro.text isEqualToString:@""]) {
UIAlertController *omitAlert = [UIAlertController alertControllerWithTitle:@"message omit" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[omitAlert addAction:okAction];
[self presentViewController:omitAlert animated:YES completion:nil];
}
else {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
Animation *animation = [NSEntityDescription insertNewObjectForEntityForName:@"Animation" inManagedObjectContext:appDelegate.persistentContainer.viewContext];
animation.name = _addView.name.text;
animation.time = _addView.time.text;
animation.number = _addView.number.text;
animation.country = _addView.country.text;
animation.intro = _addView.intro.text;
NSData *imageData = UIImagePNGRepresentation(_addView.imageView.image);
animation.image = imageData;
animation.like = _addView.like.on;
[appDelegate saveContext];
[self.navigationController popViewControllerAnimated:YES];
}
}
错误:
2017-11-09 17:50:34.492561+0800 动画[3807:1835973] -[NSAsynchronousFetchResult 计数]:无法识别的选择器发送到实例 0x1c8087670 2017-11-09 17:50:34.495239+0800 动画[3807:1835973] *** 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[NSAsynchronousFetchResult count]: 无法识别的选择器发送到实例 0x1c8087670'
带有 fetchRequestWithEntityName: 调用的代码如下:
- (NSArray *)animationArr {
if(_animationArr == nil) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Animation"];
NSError *error = nil;
_animationArr = [appDelegate.persistentContainer.viewContext executeRequest:request error:&error];
}
return _animationArr;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.animationArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellID = @"cellID";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
self.animation = [self.animationArr objectAtIndex:indexPath.row];
cell.cellName.text = self.animation.name;
return cell;
}
我检查了很多次,但我找不到错误。 提前致谢。
【问题讨论】:
-
该错误似乎与该代码无关。
-
是的...我找不到任何与 NSAsynchronousFetchResult 相关的代码。和 FetchRequest 有关系吗?
-
@LeeG4ng 顾名思义,我猜
NSAsynchronousFetchResult只是内部iOS SDK 类的名称。你在哪里取的? -
@Larme 我已经使用 etchRequestWithEntityName: 方法添加了代码。但是当我不调用这个方法时,我也得到了错误。
-
您正在使用 NSAsynchronousFetchResult 的对象而不是 NSArray 或 NSMutablearray 来获取您的应用程序在 animationArr.count 处崩溃的项目计数检查 animationArr 数据类型是否正确,是否为数组
标签: ios objective-c core-data