UISplitViewController:如何获取工具栏如果细节控制器是UITableView? [英] UISplitViewController: how to get toolbar if details controller is UITableView?

查看:121
本文介绍了UISplitViewController:如何获取工具栏如果细节控制器是UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了Apple的 UISplitViewController 中交换细节视图,似乎他们把 UIToolbar 在每个细节控制器。然后,如果设备旋转,他们隐藏工具栏或显示它,并添加一个弹出按钮,将显示根控制器。

I checked out Apple's example on how to exchange detail views in the UISplitViewController and it seems that they put the UIToolbar in every detail controller. Then, if the device is rotated, they hide the toolbar or show it and add a popover button which will show the root controller.

我想采用这种模式,使用工具栏中的按钮在弹出框中显示我的根控制器,但不幸的是,我的详细控制器都是 UITableViewControllers ,它们不允许添加除表视图之外的其他UI元素。那么我该如何处理呢?有一个例子吗?

I'd like to adopt this pattern to show my root controller in a popover using a button in the toolbar, but unfortunately, my detail controllers are all UITableViewControllers and they do not allow adding other UI elements than a table view. So how do I deal with that? Is there an example around?

René

推荐答案

由自己决定:不要在您的NIB中使用UITableViewController和UITableView作为根视图,因为您无法向表视图中添加UIToolbar。

I think I figured out by myself: DON'T use a ´UITableViewController´ and a UITableView as root view in your NIB, as you cannot add a UIToolbar to the table view.

:在NIB中,放一个标准视图,并拖动一个UIToolbar和一个UITableView就可以了。
将标准视图连接到控制器的查看插座。
添加另一个插座,并使其成为UITableView。将表视图连接到它。

Instead: In the NIB, put a standard view and drag a UIToolbar and a UITableView on it. Connect the standard view to the controller's "view" outlet. Add another outlet and make it a UITableView. Connect the table view to it.

在代码中:让您的控制器继承自UIViewController,而不是从UITableViewController继承。
向您的控制器添加一个属性,以使TableView看起来与UITableViewController兼容。

In the code: Let your controller inherit from UIViewController and not from UITableViewController. Add a property to your controller to get the TableView to make it look compatible to UITableViewController.

public UITableView TableView
{
get { return this.viewTableView; }
}

在viewDidRotate事件时,您必须调整表视图的宽度和高度现在(UITableViewController以前为你做了那个工作):

Upon the viewDidRotate event you will have to adjust the table views width and height now (UITableViewController did that job for you before):

this.TableView.Frame = new RectangleF(0, 44, this.SuperView.Frame.Width, this.SuperView.Frame.Height);

来自父视图工具栏的44像素com。

The 44 pixels com from the parent view's toolbar.

我不想错过UITableViewController。我知道在编辑时,有一些问题像自动滚动,但在我的情况下,这根本不需要。

I don't miss UITableViewController. I know there are some issues like automatic scrolling when editing, but in my case this is simply not needed.

René

这篇关于UISplitViewController:如何获取工具栏如果细节控制器是UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆