-4

我正在构建一个iPad应用程序。我想让其中一个视图 (xib) 显示几个表,在运行时将不同的数据填充到每个表中,即,当视图加载时,我想为每个表运行查询并将查询结果作为行返回到相关表格。所以对于tableA,我会运行queryA并返回datasetA、tableB、queryB、datasetB等等。我怎样才能做到这一点?你能给出示例代码吗?我还希望能够与表格进行交互,例如,选择一行并将信息传递到另一个屏幕。

4

2 回答 2

0

只需创建四个表并将它们放在视图上,将 tableview 委托和数据源设置为 self。给每个表一个特定的标签。在数据源或委托方法中,在执行操作之前检查该特定 tableview 的标记并运行与其相关的查询。例如:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
// The header for the section is the region name -- get this from the region at the section index.
if (tableView.tag ==12) {
    return @"comments:";
}
else
{
return sectiontitle;
}
}

其中一个表有 tag=12 ,如果标签为 12 则执行与该表相关的操作,否则与其他表相关的操作。

于 2013-09-13T12:42:14.667 回答
0

比 BalaChandra 的答案更简单的方法(它是正确的):

我想你的 UITableViews 是实例变量(甚至是属性)。因此,如果您已实例化表视图,例如:

UITableView *tableViewA = [[UITableView alloc] init...];
UITableView *tableViewB = [[UITableView alloc] init...];

例如,您不需要将标签设置为表格视图。在 UITableViewDelegate/UITableViewDataSource 方法中,您可以检查哪个 tableView 是这样的:

if (tableView == tableViewA) {
    // Do something with tableA... 
}
else if (tableView == tableViewB) {
    // Do something with tableB...
}
...
于 2013-10-02T10:47:23.913 回答