我有一个视图控制器,它是我的HomeViewController,我之间有一个模态segue。
这是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添加一个导航控制器......它只是一个表视图,我希望它有一个导航控制器,我应该怎么做?
另外,为什么xcode告诉我我的模态方法presentModalViewController已被弃用?
TNX
答案 0 :(得分:2)
创建UINavigationController
的新实例,将StackTableViewController
作为其rootViewController
。然后出现导航控制器:
- (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:
替换。