本文介绍了NSMetadataQueryDidUpdateNotification不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我我从iOS 5开发人员手册中改编的以下代码有什么问题吗

Can someone tell me what is wrong with the following code which I adapted from iOS 5 Developer's Cookbook

- (void) startMonitoringUbiquitousDocumentsFolder
{
    // Remove any existing query – stored in local instance variable
    if (alertQuery) [alertQuery stopQuery];

    // Search for all file names
    alertQuery.predicate = [NSPredicate predicateWithFormat: @"NSMetadataItemFSNameKey == '*'"];
    alertQuery.searchScopes = [NSArray arrayWithObject:
   NSMetadataQueryUbiquitousDocumentsScope];

    // Subscribe to query updates

    [[NSNotificationCenter defaultCenter]
             addObserver:self
             selector:@selector(alertUserToUpdates:)
             name:NSMetadataQueryDidUpdateNotification
             object:nil];

    [alertQuery startQuery];
}

- (void) alertUserToUpdates
{
    NSLog(@"Contents changed in ubiquitous documents folder");

    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"Home Monitor"
                              message:@"Something's going on."
                              delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:@"Check Recording", nil];
    [alertView show];
    [self stopMonitoringUbiquitousDocumentsFolder];
}

我得到一个异常,该异常表明选择器alertUserToUpdates:无法识别.为什么它无法识别显然在它旁边的方法?

I get an exception which says the selector alertUserToUpdates: is unrecognized. Why can't it recognize the method which is obviously right next to it?

2013-04-29 18:07:22.458 eyeFun[8231:907] -[RGPViewController alertUserToUpdates:]: unrecognized selector sent to instance 0x1fd506a0
2013-04-29 18:07:22.462 eyeFun[8231:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RGPViewController alertUserToUpdates:]: unrecognized selector sent to instance 0x1fd506a0'
*** First throw call stack:
(0x337eb3e7 0x3b4e6963 0x337eef31 0x337ed64d 0x33745208 0x3373c349 0x34053b7f 0x340ab327 0x3373c349 0x337b810f 0x37880de9 0x340fa657 0x337c0857 0x337c0503 0x337bf177 0x3373223d 0x337320c9 0x3731133b 0x3564e2b9 0x465b5 0x3b913b20)
libc++abi.dylib: terminate called throwing an exception

推荐答案

因为它不是在其旁边.

您要告诉它使用名为alertUserToUpdates:的选择器.您有一个名为alertUserToUpdates的方法. :很重要-它表示该方法接受一个参数,但实际方法不接受参数.

You're telling it to use a selector named alertUserToUpdates:. You have a method named alertUserToUpdates. The : is significant-- it says that the method takes one argument, but the actual method doesn't take arguments.

您的方法应采用NSNotification类型的参数.

Your method should take an argument of type NSNotification.

这篇关于NSMetadataQueryDidUpdateNotification不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 14:47