Joh*_*dah 48 objective-c ios xcode4.6
我正在使用Xcode 4.6.1在Objective-C上编码.我想知道当我在2个View控制器之间创建模态segue时如何保持导航栏显示,因为我在故事板中执行segue,当我运行应用程序时,第二个视图控制器的导航栏消失了,我在那个酒吧上有一个完成按钮,但我看不到它.
Sal*_*sum 83
只需Navigation Controller在模态视图控制器中添加另一个.按照步骤
Modal View Controller Editor menuEmbed InNavigation Controller运行该应用程序.现在它应该完美地工作.
希望这能解决你的问题.
rde*_*mar 58
模态segue占据整个屏幕,因此呈现控制器中的任何导航栏,工具栏或标签栏都将被掩盖.如果您想在此模态控制器上使用导航栏,则需要专门为其添加一个导航栏,并将所需的任何按钮添加到该新导航栏(或工具栏).如果你不想这样做,那么不要以模态方式呈现它,做一个推动它.
Chr*_*mit 17
您只需执行以下操作即可显示导航栏:
Objective-C的
UINavigationController alloc]initWithRootViewController:modalVC];
Run Code Online (Sandbox Code Playgroud)
SWIFT 3
let modelVC = self.storyboard?.instantiateViewController(withIdentifier: "modalVC") as! ModalVC
let navBarOnModal: UINavigationController = UINavigationController(rootViewController: modalVC)
self.present(navBarOnModal, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这将显示带导航栏的模态视图控制器.关于Objective-C的知识是有限的,所以我没有写出演示的部分.你应该能够找到一个.;)
希望这可以帮助!
小智 10
在iOS 8中有一种更好的方法.您可以使用自适应演示样式:
Objective-C的:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationFullScreen;
}
- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: controller.presentedViewController];
return navController;
}
Run Code Online (Sandbox Code Playgroud)
迅速:
UIPopoverPresentationControllerDelegate
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.FullScreen
}
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
var navController = UINavigationController(rootViewController: controller.presentedViewController)
return navController
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特4:
extension MyViewController: UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.fullScreen
}
func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
return UINavigationController(rootViewController: controller.presentedViewController)
}
}
Run Code Online (Sandbox Code Playgroud)
在准备segue方法时设置委托:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if let adpostVC = segue.destinationViewController as? XXXController {
let popPC = adpostVC.popoverPresentationController
popPC?.delegate = self
Run Code Online (Sandbox Code Playgroud)
小智 5
swift版本:
按照步骤:
覆盖prepareForSegue()
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "goToYourController" {
let navigation: UINavigationController = segue.destinationViewController as! UINavigationController
var vc = YourViewController.init()
vc = navigation.viewControllers[0] as! YourViewController
//if you need send something to destnation View Controller
//vc.delegate = self
}
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
53483 次 |
| 最近记录: |