如何在TableViewController上添加UIView [英] How do I add an UIView above a TableViewController

查看:89
本文介绍了如何在TableViewController上添加UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的tableview上面显示一个UIView,出于测试目的,我使用了一个Searchbar(以消除我的代码可能出现的任何问题)。

I would like to display an UIView above my tableview, for testing purposes I have used a Searchbar (to eliminate any possible problems with my code).

我的设置:

标签栏控制器

     MyCustomTableViewController

        查看

             TableView (用于自定义单元格高度)

             Searchbar

My setup:
Tab bar controller
    MyCustomTableViewController
        View
            TableView (for customizing cell height)
            Searchbar

我已经将搜索栏定位在窗口的顶部,然后拉下桌面视图,使其位于搜索栏的正下方。

所以在IB中,一切看起来都很棒。

但是当我启动应用程序时,tableview会占用整个屏幕,搜索栏无处可寻。

I have positioned the searchbar at the top of the "window" and pulled down the tableview so that it is positioned directly below the searchbar.
So in IB everything looks great.
But when I start the application the tableview takes up the whole screen, and the searchbar is nowhere to be found.

我对iPhone开发很新,所以可能有一个非常简单的解决方案(?)。

/ Jimmy

I'm quite new to IPhone development so there might be a very simple solution(?).
/Jimmy

推荐答案

真正简单的解决方案是:

The really simple solution is to:


  • 创建一个自定义UIViewController子类实现 UITableViewDelegate UITableViewDataSource 就像 UITableViewController 确实。还要添加 UITableView outlet。

  • 在XIB文件中,放置搜索栏和 UITableView 在视图控制器的视图中。

  • 将表视图连接到自定义中的 tableView 插座UIViewController

  • UITableView 的委托和数据源连接到文件所有者(您的自定义<$ c) $ c> UIViewController 实现正确的委托)

  • Create a custom UIViewController subclass that implements UITableViewDelegate and UITableViewDataSource just like UITableViewController does. Also add a UITableView outlet.
  • In the XIB file, put your searchbar and UITableView inside the view controller's view.
  • Connect the table view to the tableView outlet in your custom UIViewController
  • Connect the UITableView's delegate and datasource to the File's Owner (your custom UIViewController that implements the right delegates)

你现在有一个自定义视图控制器只能工作比如 UITableViewController 除了你完全控制它的布局。您以相同的方式实现代理。

You now have a custom view controller that works just like a UITableViewController except you have total control over it's layout. You implement the delegates in the same way.

这篇关于如何在TableViewController上添加UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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