问题
如图所示,该页面是一个tableView , 整个播放画面是一个
tableViewCell
然而切换横竖屏的时候,播放画面不见了,通过调试发现
播放画面的承载视图移到其他非当前cell上面了,
进而发现是切换横竖屏的时候走了cellForrow 方法,
导致重用出了问题。
然后问题就是为什么会执行cellForrow方法
后来发现是返回的高度有问题
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.view.bounds.height;
}
这段代码的问题就是,在横竖屏的时候,
返回的高度差别是很大的,一屏展示的cell数量就不同了,
从而导致执行cellForrow 方法,
修复
原理: 使横竖屏情况下返回的高度不变,
从而不需要重新绘制cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return SCREEN_HEIGHT;
}
注意:
宏定义
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height>[[UIScreen mainScreen] bounds].size.width?[[UIScreen mainScreen] bounds].size.height:[[UIScreen mainScreen] bounds].size.width)