简体   繁体   中英

UINavigationViewController control UIContainerView embed segue

I have the following scenario: Main.storyboard

A UIViewController is embedded inside a UINavigationViewController. The UIViewController has a UINavigationItem attached to it and has a UIContainerView as a subview. The UIContainerView has a embed segue to a UITableViewController with some static rows.

How can I make it so that when the user presses the Advanced row's little arrow image on the right, the UIViewContainer's embed segue get changed to reference another UITableViewController and have a Back button on the UINavigationController so that the user can navigate back to the original UITableViewController(with animations)?

Basically I want the user to be able to switch between Settings and Advanced Settings.

Things I have tried : I tried having the container view have an embed segue to an UINavigationController. The first UITableViewController was set up to have a root-view controller segue relationship with the UINavigationController. I then made a show segue between the arrow (button) and another UITableViewController. This way I was able to transition between settings -> advanced settings -> settings, but I had double navigation bars. One is the bar I want, the white one on top, and the other is a gray one that appears below and where the back button is displayed. I want it to be a single navigation bar (the white one).

设定画面 高级设置屏幕

I have no problem using code to achieve what I want (Objective-C or Swift).

In the end I did it by code by adding the back button and dismissing the "Advanced Settings" view controller programmatically. I achieved this by created a show segue to the "Advanced Settings" UITableView. I then subclassed the UITableViewController:

@implementation AdvancedSettingsController

- (void)viewDidLoad
{
  [super viewDidLoad];

  UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
  self.navigationController = (UINavigationController*)self.parentViewController;
  self.parentViewController.parentViewController.navigationItem.leftBarButtonItem = backButton;
}

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

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Incomplete implementation, return the number of sections
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete implementation, return the number of rows
    return 0;
}

-(IBAction)goBack
{
  [self.navigationController popViewControllerAnimated:YES];
}
@end

I just wanted to have it be done using the Xcode builder to automate the process a bit, because I do not like the self.parentViewController.parentViewController thing, because if I change my controllers this will stop working and is a little hard to read.

End result (webm) - https://webmshare.com/m8Kne

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM