2010-01-15 73 views
3

我想在UI视图上使用并显示两个表。请让我知道如何做到这一点。任何相同的代码也将被赞赏。如何在UI视图中显示两个表

感谢, 桑迪普

+2

你确定你不想只是使用“部分”,而不是? – bpapa 2010-01-15 15:53:22

回答

16
  1. 添加2个UITableViews到您的视图中的IB和它们在文件所有者连接到2个不同的网点(或简单地分配不同的标签属性)。
  2. 为它们设置委托和数据源(对于两者可以是相同的视图控制器)。你做以下
  3. 在委托/数据源的方法:

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{  
        if (tableView == myFirstTable) 
         // return value for 1st table 
        if (tableView == mySecondTable) 
         // return value for 2nd table 
        return 0; 
    } 
    

,或者如果您使用标签的做法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    switch(tableView.tag){ 
     case firstTag: 
      // return value for 1st table 
     case secondTag: 
      // return value for 2nd table 
    } 
    return 0; 
} 
相关问题