iOS如何在一个view上 显示两个tableview

我想在一个view上显示两个tableview
一个在左边 一个在右边 怎么做到呢?

我给你一个思路。
1.创建一个View-based Application,比如test
2.在打开testViewController.xib
3.在view上放上两个tableview,一个在左,一个在右,只需要拖动鼠标来改变大小和位置。
当然你可以使用代码来创建两个uitableview,然后加到view上,用代码指定位置和大小。
其实我想你的问题是如何在一个viewcontroller中为两个tableview指定数据源和代理。
下面就是答案。
4.在testViewController.h中修改代码如下:
@interface testViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> {
@public
int testiv;
UITableView *tab1;
UITableView *tab2;
}
@property(nonatomic, retain)IBOutlet UITableView *tab1;
@property(nonatomic, retain)IBOutlet UITableView *tab2;
5.在testViewController.m中改一下代码
#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if(tableView == tab1)
return 1;
else {
return 2;
}

}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(tableView == tab1)
return 1;
else {
return 2;
}
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if(tableView == tab1)
cell.textLabel.text = @"111";
else {
cell.textLabel.text = @"222";
}
    }
    
// Configure the cell.

    return cell;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Qt C++中,你可以使用QSqlRelationalTableModel和QSqlTableModel来在同一个tableView显示不同的数据表。 QSqlTableModel用于显示单个数据表的数据。你可以使用setTable()方法设置要显示的数据表,然后使用select()方法从数据库中检索数据。例如: ```cpp QSqlTableModel *model = new QSqlTableModel(this); model->setTable("my_table"); model->select(); ui->tableView->setModel(model); ``` 要在同一个tableView显示多个数据表,你可以使用QSqlRelationalTableModel。QSqlRelationalTableModel可以显示多个相关联的数据表的数据。你可以使用setTable()方法设置要显示的主数据表,然后使用setRelation()方法将其他数据表与主数据表相关联。例如: ```cpp QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this); model->setTable("orders"); model->setRelation(1, QSqlRelation("customers", "id", "name")); model->setRelation(2, QSqlRelation("products", "id", "name")); model->select(); ui->tableView->setModel(model); ``` 在此示例中,orders表是主数据表,而customers和products表是相关联的数据表。setRelation()方法将customers表与orders表的customer_id列相关联,将products表与orders表的product_id列相关联。这样,tableView显示orders表中的数据,并且将customer_id和product_id列中的值替换为相关联的表中的数据。 请注意,使用QSqlRelationalTableModel时,你需要在数据库中设置外键约束来确保正确的关联。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值