DQKFreezeWindowView
DQKFreezeWindowView copied to clipboard
在滑动表格时 row 的代理方法询问 row=-1 时的值
- (DQKRowViewCell *)freezeWindowView:(DQKFreezeWindowView *)freezeWindowView cellAtRow:(NSInteger)row
在横向滑动时,给的 row 的值怎么会是 -1 呢?
另外,DQKRowViewCell *rowCell = [freezeWindowView dequeueReusableRowCellWithIdentifier:rowReuseId forRow:row];
为什么会数组越界:比如在 DQKFreezeWindowViewExample 中将 row 设置为10,则在- (DQKRowViewCell *)freezeWindowView:(DQKFreezeWindowView *)freezeWindowView cellAtRow:(NSInteger)row
中应该拿到的是0 ~ 9,但实际打印可以得到的范围是 -1 ~ 10,这明显产生了数组越界问题。
补充,获取 section 的数据源方法也有数值越界行为。
我看了下源码,是这个地方加1和减1造成的,
[self addSectionViewCellWithSection:section];
[self addSectionViewCellWithSection:sectionMax];
[self addRowViewCellWithRow:row];
[self addRowViewCellWithRow:rowMax];
[self removeSectionViewCellWithSection:section - 1];
[self removeSectionViewCellWithSection:sectionMax + 1];
[self removeRowViewCellWithRow:row - 1];
[self removeRowViewCellWithRow:rowMax + 1];
如果去掉加1或者减1,section 的内容就会在滑动的时候变空白,你可能希望通过+1、-1这种trick的方式解决问题,但实际上引入了新的问题,那就是数组越界,这个问题实际上更严重,它会导致闪退。据我分析,你的实际难点是滑动时 section 变空白,而目前你回避了这个难点。由于时间关系我就没有深入看了,有空我再看看其他部分的源码。
Orz 欢迎来提 pr ,年轻的时候写的