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
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值