后台获取iOS UIBackgroundFetchResult无法识别选择器

后台获取iOS UIBackgroundFetchResult无法识别选择器,ios,objective-c,background-fetch,Ios,Objective C,Background Fetch,我正在跟踪并得到一些错误。我已经创建了一个基本应用程序,它可以显示带有源数据的表,而且它UIRefreshControl运行良好 然后我开始创建它的后台抓取过程。我已经启用了它的后台功能,在appDelegate上设置了最小间隔时间,并实现了application:performFetchWithCompletionHandler:方法 - (void)application:(UIApplication *)application performFetchWithCompletionHandl

我正在跟踪并得到一些错误。我已经创建了一个基本应用程序,它可以显示带有源数据的表,而且它
UIRefreshControl
运行良好

然后我开始创建它的后台抓取过程。我已经启用了它的后台功能,在appDelegate上设置了最小间隔时间,并实现了
application:performFetchWithCompletionHandler:
方法

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    MyTableViewController *viewController = (MyTableViewController *)self.window.rootViewController;
    [viewController fetchNewDataWithCompletionHandler:^(UIBackgroundFetchResult result) {
        completionHandler(result);
    }];
}
我建立了这个项目,但仍然工作得很好。然后,我想通过复制现有的项目方案来测试它的后台进程,并由于后台获取事件启用选项启动。我按了run,由于无法识别选择器,它给了我错误

[UINavigationController fetchNewDataWithCompletionHandler:]: unrecognized selector sent to instance 0x7fb99280b800
这是我的
fetchNewDataWithCompletionHandler

- (void)fetchNewDataWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    XMLParser *xmlParser = [[XMLParser alloc] initWithXMLURLString:NewsFeed];
    [xmlParser startParsingWithCompletionHandler:^(BOOL success, NSArray *dataArray, NSError *error) {
        if (success) {
            NSDictionary *latestDict = [dataArray objectAtIndex:0];
            NSString *latestTitle = [latestDict objectForKey:@"title"];

            NSDictionary *existingDict = [self.arrNewsData objectAtIndex:0];
            NSString *existingTilte = [existingDict objectForKey:@"title"];

            if ([latestTitle isEqualToString:existingTilte]) {
                completionHandler(UIBackgroundFetchResultNoData);
                NSLog(@"No new data found");
            }
            else {
                [self performNewFetchedDataActionsWithDataArray:dataArray];
                completionHandler(UIBackgroundFetchResultNewData);
                NSLog(@"New data was fetched");
            }
        }
        else {
            completionHandler(UIBackgroundFetchResultFailed);
            NSLog(@"Failed to fetch");
        }
    }];
}

我不知道这里发生了什么,我的
fetchNewDataWithCompletionHandler
发生了什么?。任何帮助都将不胜感激。谢谢。

您需要将viewController设置为rootViewController

MyTableViewController *viewController = [[MyTableViewController alloc] init];
self.window.rootViewController = viewController;
然后配置tableView:cellForRowAtIndexPath:以支持将单元格标识符出列

static NSString *cellIdentifier = @"cellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}

如果这是工作,请告诉我

错误显示您的rootViewcontroller是UINavigationController。您的方法存在于“MyTableViewController”类中,因此请确保您创建了该类对象。已在MyTableViewController类中创建fetchNewDataWithCompletionHandler。怎么了?你用错班级了。您应该使用“MyTableViewController”而不是“UINavigationController”。请看我的performFetchWithCompletionHandler:,我使用MyTableController创建viewController对象。“我错了吗,@nadim?很高兴帮助你,@yankoo”