在 UITableView 上方添加工具栏,以便在 UISplitViewController 详细视图中使用

发布于 2024-09-07 07:03:56 字数 90 浏览 2 评论 0原文

我想使用表视图作为 UISplitViewController 中的详细信息窗格。如何将工具栏放在顶部?我希望能够以与非表格详细视图相同的方式添加栏按钮项目。 谢谢。

I want to use a table view as the detail pane in my UISplitViewController. How do I put the toolbar at the top? I want to be able to add bar button items in the same way as my non-table detail views.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日记撕了你也走了 2024-09-14 07:03:56

我对这个问题的沮丧在于尝试使用 UITableViewController 类,它不允许您添加其他 UI 元素(如工具栏)。我通过创建一个 UIViewController 对象并将工具栏和表格视图分别添加到其笔尖来解决这个问题。然后我让 ViewController 实现表视图的委托和数据源方法。效果很好。

My frustration with this problem lay in trying to use the UITableViewController class, which does not allow you to add other UI elements like a toolbar. I solved it by creating a UIViewController object and adding the toolbar and table view to its nib individually. I then had the ViewController implement the table view's delegate and data source methods. Works great.

红玫瑰 2024-09-14 07:03:56

常见的范例是使用 UINavigationControllers 作为主页和详细信息页面的顶级控制器。

所以视图层次结构看起来像这样(粗略地说)

  • 应用程序窗口
    • UISplitViewController
      • 主控:UINavigationController
        • 有您的自定义控制器(tableView 或 UIView)
      • 详细信息:UINavigationController
        • 有您的自定义控制器(UITableViewCOntroller / UIVIEWcontroller)

希望这个粗略的图表有意义。

将 UINavigationController 作为顶级控制器的好处是,您可以“免费”获得工具栏。

   self.navigationController.toolbar

common paradigm is have UINavigationControllers as the top level controllers for master and detail pages.

So the view hiearchy looks like this (loosly speaking)

  • Application Window
    • UISplitViewController
      • master : UINavigationController
        • has your custom Controller (tableView or UIView)
      • detail : UINavigationController
        • has your custom controller (UITableViewCOntroller / UIVIEWcontroller)

hope this crude diagram makes sense.

THe perk of having UINavigationController as the top level controller, you get the Toolbar for 'free'.

   self.navigationController.toolbar
七堇年 2024-09-14 07:03:56

我用另一种方式解决了这个问题:如果没有导航栏,我只需在 tableView 顶部添加一个工具栏,然后更改第一部分中标题的高度。唯一的问题是工具栏随 tableView 一起滚动。

将其添加到 TableViewController 的 ViewDidLoad

if (! self.navigationController.navigationBar) {
    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
    toolBar.barStyle = UIBarStyleBlackOpaque;
    [self.tableView addSubview:toolBar];
}

添加此方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection: (NSInteger)section
{
    return 50;
}

I solved this other way: in case of absense of navigationBar I just add a toolbar at the top of tableView and I change the height for header in first section. The only problem is that toolbar scrolls with the tableView.

Add this to ViewDidLoad of your TableViewController

if (! self.navigationController.navigationBar) {
    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
    toolBar.barStyle = UIBarStyleBlackOpaque;
    [self.tableView addSubview:toolBar];
}

Add this method:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection: (NSInteger)section
{
    return 50;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文