Ios cellForRowAtIndexPath在设备旋转期间未调用

Ios cellForRowAtIndexPath在设备旋转期间未调用,ios,uitableview,delegates,Ios,Uitableview,Delegates,我有一个带有一些委托方法的UITableView。第一次加载时一切正常,但在旋转过程中,我看到方法cellForRowAtIndexPath不记得了。为什么? 我的委托方法是: -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ //..... } -(CGFloat) tableView:(UITableView *)tableView hei

我有一个带有一些委托方法的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{
      //.......
  }

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

处理旋转有3个选项:

  • 使用自动布局
  • 使用弹簧和支柱
  • 替代布局子视图(在旋转时将调用该视图)

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

在旋转发生后,您需要使用
[tableView reloadData]
内的
shouldAutorotateToInterfaceOrientation
方法手动刷新表格数据