【问题标题】:cellForRowAtIndexPath not call during device rotation设备旋转期间不调用 cellForRowAtIndexPath
【发布时间】:2012-10-30 14:41:17
【问题描述】:

我有一个带有一些委托方法的 UITableView。在第一次加载期间一切正常,但在旋转期间我看到方法 cellForRowAtIndexPath 不记得了。为什么? 我的委托方法是:

-(NSInteger)tableView:(UITableView *)tableView
  numberOfRowsInSection:(NSInteger)section{
       //.....
   }

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     //......
 }
 - (UITableViewCell *)tableView:(UITableView *)aTableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath{

     //...This method is not called during the rotation of the device...

  }

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
      //.......
  }

【问题讨论】:

    标签: ios uitableview delegates


    【解决方案1】:

    轮换发生后,您需要在shouldAutorotateToInterfaceOrientation 方法中使用[tableView reloadData] 手动刷新表数据。

    【讨论】:

      【解决方案2】:

      只有当单元格即将在屏幕上可见并且表格请求它时,才会调用该方法。一旦它在视图中,它将不会被再次调用,直到它滚动出视图然后再返回。

      您有 3 个选项来处理旋转:

      • 使用自动布局
      • 使用弹簧和支柱
      • 覆盖 layoutSubviews(将在旋转时调用)

      您选择的内容取决于您的单元格布局的复杂程度。另外,请确保表格在旋转时调整大小,否则单元格将不会看到大小变化。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-11
        • 1970-01-01
        • 2011-11-09
        相关资源
        最近更新 更多