[英]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.