简体   繁体   English

在设备轮换期间不调用cellForRowAtIndexPath

[英]cellForRowAtIndexPath not call during device rotation

I have a UITableView with some delegate methods.During load for the first time it's all ok, but during the rotation I saw that the method cellForRowAtIndexPath doesn't recall. 我有一个带有一些委托方法的UITableView。第一次加载时一切正常,但在旋转过程中我看到方法cellForRowAtIndexPath不记得。 Why? 为什么? My delegate method are: 我的委托方法是:

-(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{
      //.......
  }

您需要在使用shouldAutorotateToInterfaceOrientation方法中的[tableView reloadData]进行旋转后手动刷新表数据。

That method is only called when the cell is about to become visible on the screen and the table requests it. 只有当单元格即将在屏幕上显示并且表格请求它时,才会调用该方法。 Once it is in the view, it will not be called again until it has scrolled out of view and then back. 一旦它在视图中,它将不再被调用,直到它滚出视图然后返回。

You have 3 options for handling the rotation: 您有3个处理轮换的选项:

  • Use AutoLayout 使用AutoLayout
  • Use Springs & Struts 使用Springs&Struts
  • Override layoutSubviews (which will get called on a rotation) 覆盖layoutSubviews(将在轮换时调用)

What you choose will depend on how complex your cell layout is. 您选择的内容取决于您的单元格布局的复杂程度。 Also, make sure the table resizes on the rotation, otherwise the cells won't see a size change. 此外,请确保表格在旋转时调整大小,否则单元格将不会看到大小更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM