iPad - 同一屏幕上有多个 UITableView [英] iPad - More than one UITableView in the same screen

查看:20
本文介绍了iPad - 同一屏幕上有多个 UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 iPad 编写应用程序,我必须在同一个屏幕中放置两个单独的 UITableView.对于这个应用程序,由于需要,我不能将 UITableView 分成两部分.它必须是两个分开的.那么,在这种情况下,我如何填充 UITableView 的行.我可以在单独的类中创建一个 DataSource 和 Delegate,一个用于第一个 UITableView,另一个用于第二个 UITableView 的 DataSource 和 Delegate 类,或者有其他更优雅的方法吗?

I coding app from iPad and I have to put two separate UITableView in the same screen. For this app I can´t put the UITableView and divid in two sections for requisits reason. It must be two separated. Well, in this case how I can fill the rows of UITableView. Can I have create a DataSource and Delegate in separate classes, one for a first UITableView and other DataSource and Delegate class for the second UITableView or have other approach more elegant?

非常喜欢.

推荐答案

您可以通过几种不同的方式来做到这一点.最直接的是使用单独的类来处理每个表视图的数据源和委托协议.

You can do this a few different ways. The most straightforward is to use separate classes to handle the datasource and delegate protocols for each table view.

或者,您可以使用单个类作为数据源和两者的委托,并检查传递给协议方法的 tableview 的标识.

Alternatively, you could use a single class as the datasource and delegate for both, and check the identity of the tableview that's passed into the protocol methods.

它看起来像这样:(我假设这段代码在你的视图控制器上.)

It would looks something like this: (I'm assuming this code is on your view controller.)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = 44.0; // default height
    if (tableView == self.myLeftTableView) {
        height = // Compute the cell height for the left table view.
    } else {
        height = // Compute the cell height for the right table view.
    }
    return height;
}

这很快就会变得丑陋,这就是我推荐第一种方法的原因.

This could get ugly quickly, which is why I'd recommend the first approach.

这篇关于iPad - 同一屏幕上有多个 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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