如何将静态UITableView设置为UIView的子视图? [英] How to setup a static UITableView as a subview of UIView?

查看:131
本文介绍了如何将静态UITableView设置为UIView的子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 TableViewController 时,我可以在故事板中设置我的所有内容。由于我使用静态单元格而不是动态属性作为我的表格视图,因此我觉得这种方法更方便,更容易实现。我挂钩新的UITableView类,只需删除所有委托方法。就像魅力一样,因为所有的内容/按钮都在故事板中设置。

When I work with a TableViewController I am able to setup all my content in storyboards. Since I use Static Cells instead of Dynamic Properties for my table view, I find this method much more convenient and easier to implement. I hook up the new UITableView class and simply delete all the delegate methods. Works like a charm as ALL of the content / buttons are being setup in storyboards.

我试图完成相同的结果,除了这次,我必须在a ViewController 并添加 TableView 作为子视图。一旦我连接了正确的类,添加我的插座连接并设置以下代理:

I am trying to accomplish the same result, except this time, I have to work within a ViewController and add a TableView as a subview. Once I hook up the right class, add my outlet connection and setup the following delegates:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MainCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;
}

如果我的 TableView 设置为动态属性

This works well if my TableView is set to Dynamic Properties :

但是当我将表格视图内容更改为 静态单元格 并删除委托方法时,我的应用程序崩溃了。那么,如何将静态单元格(我可以在故事板中操作)的表视图添加到我的 ViewController

But when I change the Table View content to Static Cells and delete the delegate method, my app crashes. So, How can I add a table view with Static Cells (That I can manipulate in storyboards) to my ViewController?

推荐答案

这是你可以做的。在故事板中,创建一个包含所有非tableview视图的父视图控制器,创建一个UITableViewController。在父视图控制器中,创建容器视图,删除它自动添加的视图控制器,右键单击并从容器视图拖动到UITableViewController以创建嵌入segue。您的最终结果应如下所示:

Here is what you can do. In your storyboard, create a parent view controller that contains all your non tableview views also, create a UITableViewController. In your parent view controller, create container view, delete the view controller it auto adds, and right click and drag from the container view to your UITableViewController to create an embed segue. Your end result should look something like this:

这篇关于如何将静态UITableView设置为UIView的子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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