使用 UISegementedControl 切换到不同的 UITableViewControllers [英] Switching to different UITableViewControllers with UISegementedControl
问题描述
我在导航栏中有一个带有 UISegmentedControl 的 UINavigationViewController.我想实现一个简单的切换到不同的ViewControllers 当用户按下分段控件时.
I've an UINavigationViewController with an UISegmentedControl in the navigation bar. I want to achieve a simple switching to different ViewControllers when users push on the segmented control.
我尝试了很多,但没有任何效果...考虑来源:
I've tried a lot and nothing works... Considered sources:
- MonoTouch 为 ContainerView 以编程方式实例化 ViewController
- https://stackoverflow.com/search?q=viewcontroller+intptr+handle 立>
- 还有很多谷歌研究...
整个项目都是基于故事板的!任何针对 NIB 的解决方案都没有用.
The whole project is storyboard based! Any solutions which targets NIB's aren't useful.
将 ContainerControl 添加到我的 UINavigationViewController.但在这种情况下,我只能嵌入一个控制器.以编程方式创建 Embedded-Segue 是不可能的.甚至在 IB 中设计的代码中实例化 UITableViewController 会导致空视图.因为我必须将 c'tor 从 MyTableViewController(IntPtr handle) : base(handle) 更改为空构造函数.
Adding a ContainerControl to my UINavigationViewController. But in this case I can only embed one controller. Creating a Embedded-Segue programmatically was not possible. Even more instantiating a UITableViewController in code which is designed in IB results in an empty view. Because I've to change the c'tor from MyTableViewController(IntPtr handle) : base(handle) to an empty constructor.
有人可以发布一个如何使用 UISegmentedControl 在不同 ViewController 之间切换的工作示例吗?非常感谢您的帮助.
Can someone publish a working example how to use a UISegmentedControl to switch between different ViewControllers? I appreciate all your help very much.
推荐答案
工作解决方案:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
CreateAndEmbed (TrDetailNavType.Info);
}
partial void segmentNavigationValueChanged (MonoTouch.UIKit.UISegmentedControl sender, MonoTouch.UIKit.UIEvent e)
{
CreateAndEmbed((TrDetailNavType)sender.SelectedSegment);
}
private void CreateAndEmbed(TrDetailNavType tab)
{
if (_currentViewController != null)
{
_currentViewController.View.RemoveFromSuperview ();
_currentViewController.RemoveFromParentViewController();
}
string id;
switch (tab)
{
case TrDetailNavType.Info:
id = "TagesRapportDetailInfoTableViewController";
break;
case TrDetailNavType.Lohn:
case TrDetailNavType.Material:
case TrDetailNavType.Inventar:
case TrDetailNavType.Fremdleistung:
case TrDetailNavType.Regie:
id = "TagesRapportDetailDummyViewController";
break;
}
_currentViewController = (UIViewController)Storyboard.InstantiateViewController (id);
_currentViewController.View.Frame = containerDetail.Bounds;
AddChildViewController (_currentViewController);
_currentViewController.DidMoveToParentViewController (this);
containerDetail.AddSubview (_currentViewController.View);
}
这篇关于使用 UISegementedControl 切换到不同的 UITableViewControllers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!