从AppDelegate推送视图控制器 - RESideMenu类

时间:2015-11-25 14:18:21

标签: ios objective-c uinavigationcontroller appdelegate

我正在使用RESideMenu类并使用此类导航控制器的内容,并在左侧菜单中使用某些视图。

此导航是内容主视图和详细信息视图。

我希望在收到通知时从app delegate推送详细信息视图,所以我写了这个,但它没有工作。

NSString *URL = @"any url";


UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *mainNavigation = (UINavigationController *) [storyboard instantiateViewControllerWithIdentifier:@"MainNavigation"];



MainViewController *mainVC = (MainViewController *) [storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
DetailViewController *detailVC = (DetailViewController *) [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

[mainNavigation setViewControllers:@[mainVC, detailVC]];
[mainNavigation popViewControllerAnimated:YES];

[detailVC setNewsLink:URL];
[mainNavigation pushViewController:detailVC animated:YES];

任何人都可以提供帮助吗?

enter image description here

--------------------- ** 更新

RESideMenu *sideMenu = (RESideMenu *) [storyboard instantiateViewControllerWithIdentifier:@"RootViewController"];
UINavigationController *mainNavigation = (UINavigationController *) [sideMenu contentViewController];

[mainNavigation pushViewController:detailVC animated:YES];

1 个答案:

答案 0 :(得分:1)

您没有使用“当前导航控制器”并推送到详细信息。您正在实例化 new mainNavigation(非当前)并推送到Details。您需要获取当前 mainNavigation(例如,在启动时存储在属性中),然后推送到新的DetailViewController。

<强>更新

在这种情况下,您正在使用RESideMenu。你必须使用contentViewController(可能是一个UINavigatorController)并从中推送。

示例

DetailViewController *detailVC = (DetailViewController *) [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

NSString *URL = @"any url";
[detailVC setNewsLink:URL];

[((UINavigationController *)self.sideMenuViewController.contentViewController) pushViewController:detailVC animated:YES];

更新2

可能在你的AppDelegate中,RESideMenu是你的self.window.rootViewController。然后:

DetailViewController *detailVC = (DetailViewController *) [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

NSString *URL = @"any url";
[detailVC setNewsLink:URL];

RESideMenu *sideMenu = (RESideMenu *)self.window.rootViewController;
[((UINavigationController *)sideMenu.contentViewController) pushViewController:detailVC animated:YES];