简体   繁体   English

如何以编程方式在视图中嵌入导航控制器?

[英]how to embed navigation controller in a view programmatically?

I have a view controller which is my HomeViewController, and I have a modal segue between them. 我有一个视图控制器,它是我的HomeViewController,并且它们之间有模式选择。

This is the HomeViewController: 这是HomeViewController:

import "HomePageViewController.h"
#import "CreatePageViewController.h"
#import "StackTableViewController.h"
#import "PopUpView.h"


@interface HomePageViewController ()

@property (nonatomic, strong) IBOutlet UIButton *toggleButton;
@property (nonatomic, strong) CreatePageViewController *modalTest;
@property (nonatomic, strong) PopUpView *popup;

@end

@implementation HomePageViewController

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

-(void)viewDidLoad {
    [super viewDidLoad];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:Nil];
    _modalTest = [storyboard instantiateViewControllerWithIdentifier:@"ModalTest"];

    [_toggleButton addTarget:self action:@selector(go) forControlEvents:UIControlEventTouchUpInside];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hide) name:@"HideAFPopup" object:nil];
}

-(void)go {

    _popup = [PopUpView popupWithView:_modalTest.view];
    [_popup show];
}

-(void)hide {

    [_popup hide];
}
- (IBAction)pushToNextViewController:(id)sender {

    StackTableViewController *vc = [[StackTableViewController alloc]init];
    [self presentModalViewController:vc animated:YES];
}


-(void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

I want to add a navigation controller to StackTableViewController...its just a table view and I want it to have a navigation controller, how should I do this? 我想将导航控制器添加到StackTableViewController ...它只是一个表视图,并且我希望它具有导航控制器,我该怎么做?

Also, why xcode tells me my modal method presentModalViewController is deprecated? 另外,为什么xcode告诉我我的模态方法presentModalViewController已弃用?

tnx TNX

Create a new instance of UINavigationController , with your StackTableViewController as its rootViewController . 创建一个新的UINavigationController实例,将StackTableViewController作为其rootViewController Then present the navigation controller: 然后显示导航控制器:

- (IBAction)pushToNextViewController:(id)sender {

    StackTableViewController *vc = [[StackTableViewController alloc]init];
    UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:navCtrl animated:YES completion:nil];

} }

Note that presentModalViewController:animated: is deprecated because it has been replaced by presentViewController:animated:completion: . 请注意,不推荐使用presentModalViewController:animated: presentViewController:animated:completion:因为它已被presentViewController:animated:completion:取代。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式在导航控制器中嵌入视图? - How to embed a view in a navigation controller programmatically? 如何从导航控制器中嵌入的View Controller接收信息 - How to receive information from View Controller which is embed in Navigation Controller 从编辑器以编程方式获取导航控制器>嵌入>导航控制器 - Programmatically Get Navigation Controller from Editor > Embed In > Navigation Controller 如何以编程方式将下一个视图控制器推入导航控制器? - How can I push the next view controller on a navigation controller programmatically? 如何以编程方式导航视图控制器表单导航控制器 - How to Navigate view Controller form Navigation Controller Programmatically 如何在代码中以编程方式添加导航控制器而不是作为初始视图控制器 - How to add a navigation controller programmatically in code but not as initial view controller 如何在以编程方式使用导航控制器设置动画的情节提要中设置根视图控制器 - How to set root view controller in storyboard animated with navigation controller programmatically 视图控制器下方的空间,该空间嵌入在导航控制器中,该控制器嵌入在ContainerView中 - A space below view controller that is embed in a navigation controller which is embed in a ContainerView 如何在Swift Xcode 8.2中以编程方式将导航控制器嵌入到选项卡栏控制器中? - How can I embed my navigation controller into my tab bar controller programmatically in Swift Xcode 8.2? 以编程方式将导航控制器嵌入到模式视图控件中 - Embed navigation controller in modal view contriller programatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM