带两个UITableViewControllers的iPhone应用程序 [英] iphone app with two UITableViewControllers side by side

查看:46
本文介绍了带两个UITableViewControllers的iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个两个表并排的iphone应用程序,其中两个表始终可见并且可以单独滚动.这可能吗?

I am attempting to build an iphone app with two tables, side-by-side, where both tables are always visible AND individually scrollable. Is this possible?

我已经在该网站上阅读了许多类似问题的答案,人们建议并排使用两个UITableViewControllers"

I have read a number of answers to similar questions on this site where people suggest using 'two UITableViewControllers, side by side'

听起来完全符合我的需要,但我找不到任何示例.

Sounds like exactly what I need, but I can not find any examples.

我的主要问题是:如何在IB的同一屏幕上实际获得两个UITableViewController?

My main question is: how do you actually get two UITableViewControllers on the same screen in IB?

或者,通过在单个UITableViewController中并排放置两个TableView来实现此目的的正确方法是吗?

Alternatively, is the correct way to do this by having two TableViews side-by-side within a single UITableViewController?

任何帮助将不胜感激

推荐答案

尽管我从@Aadhira的上述回答中获得了初步指导,但我认为我将对可能对您有用的其他人完全回答我的问题(我明白了顺便说一下)

Although I took initial guidance from @Aadhira's answer above, I thought I'd completely answer my question for anyone else who might find this useful (I got it to work by the way)

我创建了具有以下视图/视图控制器层次结构的情节提要

I created a storyboard with the following hierarchy of views/view controllers

UITableViewController控制器-UITableView ViewContainer-UITableView左-UITableView左

UITableViewController Controller - UITableView ViewContainer -- UITableView Left -- UITableView Left

我创建了表格视图"ViewContainer"以包含"我要绘制的两个表格视图(左和右).我觉得用这种方法比较容易的原因是因为在IB中没有其他方法可以调整左和右表视图的大小,以便它们仅占据屏幕的一半.每当我将它们直接放在表格视图控制器Controller中时,它们都会占用整个宽度(我想我可以通过编程方式控制它们的宽度).将它们放在表格视图ViewContainer中可以让我调整它们的大小.

I created the table view 'ViewContainer' to 'contain' the two table views (Left and Right) which I wanted to draw. The reason I felt it was easier to do it this way is because there was no other way to resize the Left and Right table views in IB so that they only take up half of the screen widht. Whenever I I put them directly inside the table view controller Controller, they would take up the full widht (I guess I could have controlled their width programatically). Putting them inside the table view ViewContainer allowed me to resize them.

我让Controller作为Left和Right的委托和数据源.然后,在Controller内,我必须确保我有一些代码来标识正在绘制哪个表(左或右).ViewContainer在很大程度上被忽略,到目前为止,我还没有使用它

I made Controller the delegate and data source for Left and Right. Then, inside Controller, I had to make sure that I had some code to identify which table (Left or Right) is being drawn. ViewContainer is largely ignored and so far I am not using it

我将以下代码添加到numberOfSectionsInTableView,numberOfRowsInSection和cellForRowAtIndexPath

I added the following code to numberOfSectionsInTableView, numberOfRowsInSection and cellForRowAtIndexPath

 switch (tableView.tag) {
    case 100:   //the requesting object is the Left TableView
    {
        //perform functions specific to Left;         
    }
        break;
    case 200:   //the requesting object is the Right TableView
    {
        //perform functions specific to Right;         
    }
        break;    
    default:
        //error handling code
        break;
}

我将表视图的标记分别设置为Left和Right,分别设置为100和200.这使我可以正确填充左"和右"(它们包含不同的对象)

I set the tags for table views Left and Right to 100 and 200 respectively. This allowed me to populate Left and Right correctly (they contain different objects)

这篇关于带两个UITableViewControllers的iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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