[英]NSInvalidArgumentException when loading a TableViewController
[英]NSInvalidArgumentException when posting notification
我正在嘗試使用通知系統,以便在 Splitviewcontroller 中有一個詳細視圖來更新 tableview。 我宣布通知如下:
[[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 setParentViewController:]:無法識別的選擇器發送到實例 0x5a3a290”
所以我想我在如何將 detailViewController 包含在用於推送的通知中做錯了。
處理通知的方法定義似乎是錯誤的。
- (void) pushView:(UIViewController *) viewController
應該,
- (void) pushView:(NSNotification *) notification
實際通知作為參數傳遞,而不是任何視圖控制器。 要實現您想要的,請嘗試以下操作。
- (void) pushView:(NSNotification *) notification
NSDictionary *userInfo = [notification userInfo];
UIViewController *viewController = (UIViewController *)[userInfo objectForKey:@"ViewController"];
[self.navigationController pushViewController:viewController animated:YES];
}
在發布通知時,
ArticleTableViewController *articleTableView = [[ArticleTableViewController alloc] initWithCategory:catInt];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:articleTableView forKey:@"ViewController"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushView" object:nil userInfo:userInfo];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.