Uitableview 检测motionEnded:中核心数据对象的#?

Uitableview 检测motionEnded:中核心数据对象的#?,uitableview,core-data,core-motion,alertview,Uitableview,Core Data,Core Motion,Alertview,我试图在用户晃动设备时检测核心数据中的对象数量。当我尝试在motionEnded:内调用NSFetchRequest时,模拟器会在main中崩溃,并出现未知错误 在motionEnded:内部执行这样的提取是否可能 到目前为止,我掌握的代码是: - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { // see if we have albums to upload NSF

我试图在用户晃动设备时检测核心数据中的对象数量。当我尝试在motionEnded:内调用NSFetchRequest时,模拟器会在main中崩溃,并出现未知错误

在motionEnded:内部执行这样的提取是否可能

到目前为止,我掌握的代码是:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
        // see if we have albums to upload

        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Groups" inManagedObjectContext:managedObjectContext];

        [fetchRequest setEntity:entity];

        NSUInteger group_count = [managedObjectContext countForFetchRequest:fetchRequest error:nil];

        if (group_count == 0)
        {
            // show alertview
        }
        else
        {
            // show another alertview
        }

}

这很好。您可以根据手势(包括抖动手势)触发的搜索结果触发搜索和警报视图

检查您的错误是什么,然后将错误对象传递给
countForFetchRequest
方法。您的
managedObjectContext
可能为零,或者您的实体名称有问题。(“组”对实体来说是个坏名字,“组”更符合逻辑。)