[英]UINavigationViewController control UIContainerView embed segue
I have the following scenario: 我有以下情况:
A UIViewController is embedded inside a UINavigationViewController. UIViewController嵌入在UINavigationViewController内部。 The UIViewController has a UINavigationItem attached to it and has a UIContainerView as a subview.
UIViewController附加了一个UINavigationItem,并具有一个UIContainerView作为子视图。 The UIContainerView has a embed segue to a UITableViewController with some static rows.
UIContainerView在带有一些静态行的UITableViewController中嵌入了序列。
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)?
我该如何做,以便当用户按下右侧的Advanced行的小箭头图像时,UIViewContainer的嵌入顺序会更改为引用另一个UITableViewController,并在UINavigationController上具有“后退”按钮,以便用户可以导航回原始UITableViewController (带有动画)?
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. 我尝试过的事情 :我尝试过将容器视图嵌入到UINavigationController中。 The first UITableViewController was set up to have a root-view controller segue relationship with the UINavigationController.
第一个UITableViewController设置为与UINavigationController具有根视图控制器segue关系。 I then made a show segue between the arrow (button) and another UITableViewController.
然后,我在箭头(按钮)和另一个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).
使用代码实现我想要的东西(Objective-C或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.
我通过在“高级设置” UITableView中创建了一个展示区来实现此目的。 I then subclassed the UITableViewController:
然后,我将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. 我只是想使用Xcode生成器来完成该过程的自动化,因为我不喜欢self.parentViewController.parentViewController的事情,因为如果更改控制器,它将停止工作,并且有点难以阅读。
End result (webm) - https://webmshare.com/m8Kne 最终结果(webm)-https://webmshare.com/m8Kne
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.