2014-11-23 60 views
1

我有一個視圖控制器,這是我的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 

我想一個導航控制器添加到StackTableViewController ......它只是一個表視圖,我希望它有一個導航控制器,我應該怎麼辦呢?

此外,爲什麼xcode告訴我我的模態方法presentModalViewController已棄用?

TNX

回答

2

創建的UINavigationController一個新實例,你StackTableViewControllerrootViewController。然後呈現導航控制器:

- (IBAction)pushToNextViewController:(id)sender { 

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

}

注意,因爲它已被取代presentViewController:animated:completion:presentModalViewController:animated:已棄用。

相關問題