如何返回最底层的Controller

iOS 码拜 9年前 (2015-05-01) 1013次浏览 0个评论

比如:
我新建一个Tabbar Application,Tab bar Controller有两个tabItem,分别由FirstViewController和SecondViewController控制,我在SecondViewController的视图添加一个按钮,点击按钮
实现:   [self presentViewController:ThirdVC animated:YES completion:nil];
然后我在ThirdVC的视图里面添加一个按钮,点击按钮返回到FirstViewController
————————–
请问方法是什么?

如何返回最底层的Controller
20分
方法:
你可以向AppDelegate.h文件发通知来切换UITabBarController的selectedIndex
在thirdVC中,通过

[self dismissViewControllerAnimated:YES completion:nil];
//////发送通知
[NSNotificationCenter defaultCenter] postNotificationName:@"App:exchangeSelected" object:@(0)];

在AppDelegate 中 self.window.rootViewController 即为你的UITabBarController. 在AppDelegate中添加通知观察者

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exchange:) name:@"App:exchangeSelected" object:nil];  

///////通知处理的切换方法
-(void)exchange:(NSNotification *)notif {
       int index  = [notif.object intValue];
      UITabBarController *tabVC = self.window.rootViewController;
      tabVC.selectedIndex = index;
}
如何返回最底层的Controller
楼上,可不可以这样。
 [self presentViewController: FirstViewController animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
如何返回最底层的Controller
引用 2 楼 qq_26232363 的回复:

楼上,可不可以这样。
 [self presentViewController: FirstViewController animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];

显然是不可以的。目前应用是通过uitabbarcontroller的形式来组织的。而楼主想要实现的是在第二个page.上present出来第三个page.在第三个page上dismiss让第一个page处在选中状态。

如何返回最底层的Controller
楼主可以在  dismissViewControllerAnimated:YES 回到 SecondVC中 然后再直接到 First ,这时通过通知代理 都可实现

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明如何返回最底层的Controller
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!