Iphone 更改rootviewcontroller后出错+;[NSNotificationCenter听写视图类]
在更改UIWindow的RootViewController后,我出现以下错误Iphone 更改rootviewcontroller后出错+;[NSNotificationCenter听写视图类],iphone,objective-c,ios,nsnotificationcenter,Iphone,Objective C,Ios,Nsnotificationcenter,在更改UIWindow的RootViewController后,我出现以下错误 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
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时才会发生这种情况,如果我直接更改,则不会发生错误。发送到类的未识别选择器意味着没有为此类定义此类方法。尝试:
您的错误日志
是2012-10-16 15:12:35.653 repdocApp[22898:c07]由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'+[NSNotificationCenter DictionViewClass]:未识别的选择器发送到类0x1d63914
您调用了错误的方法。dictationViewClass
在ios中不存在。
这只是意味着您试图调用对应类不存在的方法(NSNotificationCenter
)。
您应该更改集合通知,如下所示
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethodWantToExcute:) name:@"NSNotificationName" object:nil];
我希望这会对你有所帮助。这不是一个真正的答案,但同样的错误会再次发生在不同的动作上,不管动画如何。
问题似乎是更改了rootviewcontroller,我将其替换为隐藏的tabbarcontroller,并在选项卡之间切换,问题就消失了。因此,我会在您的源代码中查找包含此方法的类别我有一个类别,但没有类似的方法,奇怪的是整个过程从未执行过。嗨,问题是代码中没有任何地方(我的或框架)有这样的名称,为什么只有在我删除了一个从未执行过的分支中的返回时才会发生这种情况?@Sebastian实际上,您是以错误的方式注册NSNotification该方法(
DictionViewClass
)不退出NSNotificationCenter
类,这就是为什么会出现异常。只需将dictationViewClass
替换为defaultCenter
。有关如何设置通知的详细信息,问题在于我的代码或我使用的任何框架中都没有类似的内容。@Sebastian请查看您的错误日志。2012-10-16 15:12:35.653 repdocApp[22898:c07]***由于未捕获的异常“NSInvalidArgumentException”终止应用程序,原因:'+[NSNotificationCenter DictionViewClass]:未识别的选择器发送到类0x1d63914'我搜索它,但什么也没有找到,另一方面,为什么在添加返回时错误没有显示?(但这一行始终不会执行)