【问题标题】:Issue with two UITableViews in single UIViewController单个 UIViewController 中的两个 UITableView 的问题
【发布时间】:2012-02-24 17:40:14
【问题描述】:

我见过类似的问题,但没有一个问题是相同的。

在 UIViewController 中,我有两个 UITableViews tableView1 和 tableView2(在 UIScrollView 中)。两个表上的数据源和委托都设置为 UIViewController,它实现了 UITableViewDelegate 和 UITableViewDatasource 协议。 UIViewController 本身位于 UITabBarController 中,如下所示:

  • UITabBar 控制器
    • UIViewController
      • UITableView (tableView1)
      • UIScrollView
        • UITableView (tableView2)

在 tableView:cellForRowAtIndexPath: 我检查哪个表并相应地填充:

if (tableView == _tableView1) {
    //do stuff for tableView1
} else {
    //do stuff for tableView2
}

当 UIViewController 出现时,只有 tableView1 填充了数据。点击另一个选项卡然后再次返回最终会填充 tableView2。

如果 tableView1 的委托和数据源设置为 nil,则 tableView2 永远不会被填充。似乎只有在填充 tableView1 后才会填充 tableView2。

有人可以帮忙吗?

非常感谢。

【问题讨论】:

  • 你在tableView:numberOfRowsInSection:numberOfSectionsInTableView:做同样的检查吗?
  • 你厌倦了这个吗? if (tableView == _tableView1) { //为 tableView1 做一些事情 }if (tableView == _tableView2) { //为 tableView2 做一些事情 }
  • 滚动视图中的表视图位于另一个表视图旁边?我不想使用那个 UI...
  • @jonkroll 是的,在这些方法中做同样的事情。谢谢。
  • @pKoul 谢谢,是的,也试过了

标签: ios cocoa-touch uitableview


【解决方案1】:

在我的问题中,我声明 iVar 是 _tableView1_tableView2。这些实际上是_indexTableView_tableView。将_tableView 更改为_gridTableView 似乎已经解决了这个问题。

【讨论】:

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