【问题标题】:How to display Two tables on a UI view如何在 UI 视图上显示两个表格
【发布时间】:2010-01-15 14:46:42
【问题描述】:

我想在一个 UI 视图上使用和显示两个表格。请让我知道如何做到这一点。任何相同的代码也将不胜感激。

谢谢, 桑迪普

【问题讨论】:

  • 您确定不想只使用“部分”吗?

标签: iphone uitableview uiview


【解决方案1】:
  1. 在 IB 中将 2 个 UITableView 添加到您的视图中,并将它们连接到文件所有者中的 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;
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    相关资源
    最近更新 更多