如何以编程方式在视图中嵌入导航控制器? [英] how to embed navigation controller in a view programmatically?
问题描述
我有一个View Controller,它是我的HomeViewController,并且它们之间有模式选择.
I have a view controller which is my HomeViewController, and I have a modal segue between them.
这是HomeViewController:
This is the 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
我想在StackTableViewController中添加一个导航控制器...它只是一个表视图,并且希望它具有一个导航控制器,我该怎么做?
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?
此外,为什么xcode告诉我我的模态方法presentModalViewController已弃用?
Also, why xcode tells me my modal method presentModalViewController is deprecated?
tnx
推荐答案
使用您的 StackTableViewController
作为其 rootViewController
创建 UINavigationController
的新实例.>.然后显示导航控制器:
Create a new instance of UINavigationController
, with your StackTableViewController
as its 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];
}
请注意,不赞成使用 presentModalViewController:animated:
,因为它已由 presentViewController:animated:completion:
代替.
Note that presentModalViewController:animated:
is deprecated because it has been replaced by presentViewController:animated:completion:
.
这篇关于如何以编程方式在视图中嵌入导航控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!