发布通知时出现 NSInvalidArgumentException
我正在尝试使用通知系统,以便在 Splitviewcontroller 中拥有详细视图来更新表视图。我声明通知如下:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushView:) name:@"pushView" object:nil];
和选择器本身:
- (void) pushView:(UIViewController *) viewController {
[self.navigationController pushViewController:viewController animated:YES];
}
现在,在详细视图中,我创建视图控制器并调用创建通知:
ArticleTableViewController *articleTableView = [[ArticleTableViewController alloc] initWithCategory:catInt];
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushView" object:articleTableView];
我认为这会起作用,但我收到错误:
* 由于未捕获而终止应用程序 例外 'NSInvalidArgumentException',原因: '-[NSConcreteNotification 设置ParentViewController:]: 无法识别的选择器发送到实例 0x5a3a290'
所以我想我在如何将detailViewController包含在用于推送的通知中做错了。
I am trying to use the notification system in order to have a detail view in a Splitviewcontroller to update the tableview. I declared the notification as follows:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushView:) name:@"pushView" object:nil];
and the selector itself:
- (void) pushView:(UIViewController *) viewController {
[self.navigationController pushViewController:viewController animated:YES];
}
Now, in the detailview I create the view-controller and call create the notification:
ArticleTableViewController *articleTableView = [[ArticleTableViewController alloc] initWithCategory:catInt];
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushView" object:articleTableView];
I assumed that that would work, but I get the error:
* Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'-[NSConcreteNotification
setParentViewController:]:
unrecognized selector sent to instance
0x5a3a290'
So I guess I am doing something wrong in how including the detailViewController in the notification to be used to push in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
处理通知的方法定义似乎是错误的。
应该是,
实际的通知作为参数传递,而不是任何视图控制器。要实现您想要的目标,请尝试以下操作。
并且在发布通知的同时,
The method definition for handling the notification seems to be wrong.
should be,
The actual notification is passed as the argument, not any view controllers. To achieve what you want, try the following.
And while posting the notification,