0

更改 UIWindow 的 rootViewControler 后出现以下错误。

2012-10-16 15:12:35.653 repdocApp[22898:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSNotificationCenter dictationViewClass]: unrecognized selector sent to class 0x1d63914'

奇怪的是,只有当我的代码中有一行此时永远不会执行时才会发生。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{   
    AppDelegate *app = (AppDelegate *) [[UIApplication sharedApplication] delegate];
    OverviewModel *model = [self.dataArray objectAtIndex:indexPath.row];

if (model.modelType == ModelTypeCatalog)
{
     NSLog(@"HERE");
    if (app.window.rootViewController == app.catalogViewController)
    {
        return;
    }
    // with this return no error but this branch is never executed
    // return;
    [UIView transitionFromView:app.window.rootViewController.view
                        toView:app.catalogViewController.view
                      duration:0.45f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    completion:^(BOOL finished){
                        app.window.rootViewController = app.catalogViewController;
                    }];
}
else
{
    if (app.window.rootViewController == app.catalogViewController)
    {
        [app.navigationPopoverController dismissPopoverAnimated:NO];
        [UIView transitionFromView:app.window.rootViewController.view
                            toView:app.splitViewController.view
                          duration:0.45f
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        completion:^(BOOL finished){
                            app.window.rootViewController = app.splitViewController;
                        }];
    }
}

}

我搜索了整个互联网,但我没有发现任何关于 +[NSNotificationCenter dictationViewClass] 或这可能是什么的信息。

编辑:我现在注意到,只有当我在转换中更改 rootViewController 时才会发生,如果我直接这样做,则不会发生错误。

4

3 回答 3

1

您的错误日志is 2012-10-16 15:12:35.653 repdocApp[22898:c07] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSNotificationCenter dictationViewClass]: unrecognized selector sent to class 0x1d63914

您正在调用错误的方法。dictationViewClassios中不存在。这只是意味着您正在尝试调用对应类(NSNotificationCenter)不存在的方法。您应该如下更改设置通知

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethodWantToExcute:) name:@"NSNotificationName" object:nil];

我希望它对你有帮助。

于 2012-10-16T13:31:59.903 回答
0

发送到类的无法识别的选择器意味着没有为这个类定义这样的方法。尝试:

  1. 删除该行并尝试它是否有效。
  2. 如果包含此方法,请在您的来源中查找类别
  3. 编写自己的同名空白方法
  4. 试着弄清楚这个方法的意义并实现它
于 2012-10-16T13:25:23.007 回答
0

这不是一个真正的答案,但无论动画如何,不同的动作都会再次发生相同的错误。问题似乎是rootviewcontroller的变化,我用隐藏的tabbarcontroller替换它并在选项卡之间切换,问题就消失了。

于 2012-10-19T06:40:35.417 回答