如何在一个view上 显示两个tableview
2013-08-20 15:48
323 查看
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;
}
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;
}
相关文章推荐
- iOS如何在一个view上 显示两个tableview
- 如何在一个view上 显示两个tableview
- 一个界面中如何使用两个tableView
- QTableview QSqlTableModel如何最恰当地只显示一个表中的某几个字段的数据
- 一个界面中如何使用两个tableView
- 一个界面中如何使用两个tableView
- 同一个TextView如何显示不同颜色的文字、字体大小、字体样式
- 如何创建一个Plain TableView With Section And Index
- 新建了一个用户,administrator不显示,如何让两个用户同时显示
- 如何创建一个UIImageView对象去显示图片
- swift3 一个tableview,两个section,controller写法
- 如何让两个 TextView 在 RelativeLayout 中水平居中显示
- 如何让tableView的分隔线左端顶头显示
- 在 sql查询中如何将两个字段显示在一个字段
- ios tableview不能显示最下面一个cell
- 如何利用TableView显示自定义nib中创建的UITableViewCell或子类?
- 在一个tableView 中需要自定义多种样式的cell(两种或三种),通常你如何实现,说说思路即可?
- iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)
- iOS 一个ViewController上显示2个tableView的方法
- 如何使ViewPager和其它元素显示在一个Activity里面