请问 如何在一个view上 显示两个tableview?我想在一个view上显示两个tableview
一个在左边 一个在右边 怎么做到呢? 在线等

解决方案 »

  1.   

    为何不能?
    我给你一个思路。
    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  -
    #pragma  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.   

    对了,你需要再次打开xib文件,做一下连接,就是两个tableview的datasource,delegate,reference
      

  3.   

    谢谢你了   我学会了 
    但是tableview没有点击事件
    我完成后 才发现的。。  只有Navigation View
    我要实现的是 左侧的tableview可以点击 并且可以跳转的
      

  4.   

    我也写了2个tableview,但是我的2个tableview的单元格的行数是一样的,这个怎么弄成不一样的,最好谁传个例子来,因为有些人说的方法不行,最好把自己试过可以的方法告诉我
      

  5.   

    最好还是自己重写tableview sdk中有好多例子
      

  6.   

    干脆写2个viewcontroller应该也可以吧,放在一个统一的controller里面,类似ipad里面的splitviewcontroller
      

  7.   

    按照1楼说的完全可以,设置左边的TAG值 为0,右边的为1,当发生点击事件时,判断一下这个值,再分发不同的事件,不就行了?1楼的完全可以,只是他是用Xib文件来做的,我当时全是代码写的,相信,1楼的完全可以。