开发者

Last Section Header View not painted after insertRowForIndexpath and deleteRowForIndexpath

I have a setup with sections in a UITableView which all have a custom section header view. Only one section at a time can have visible rows.

To create an effect that displays other cell rows I basically use the following function:

[self.tableView beginUpdates];

if ( sectionHeaderInsert >= 0 && sectionHeaderInsert <= numberOfSectionsInTableView ) {
    [ticketReastepsScreenView.tableView insertRowsAtIndexPaths:indexPathsInsert withRowAnimation:UITableViewRowAnimationFade];
}

[self updateTmpSelectedNumberToCurrent];

if ( sectionHeaderRemove >= 0 && sectionHeaderRemove <= numberOfSectionsInTableView ) {
    [ticketReastepsScreenView.tableView deleteRowsAtIndexPaths:indexPathsRemove withRowAnimation:UITableViewRowAnimationFade];
}

[self.tableView endUpdates];

Now what happens is that in the end the new section "opens" and the old one "closes" propperly, but: if I have more sections that fit on the screen the last section that is (partly) visible will not repaint propperly - it is completely covered in white.

All sections are asked gor new heights and I think it even asks for new views (which I hae in an array). The views are then asked to [view setNeedsDisplay];

When I scroll a bit so that the last section header disappears and then scroll it back in, it comes to life again and is visible until I change the currently open section again.

UPD: This funny behavior only appears when I do the insertRow and deleteRow together. I can also simply close one section (deleteRow) and then in a section touch-action open the new one (insertRow) and the behavior is different.

I also tried having an endUpdates and beginUpdates in between the two actions - no positive result.

UPD2: When transitioning to the fi开发者_开发知识库nal position (positions are good) I can see the last section header being painted correctly, but then disappear (no animation, simple plain white over it)


Whatever the REAL problem was - I rewrote heavy parts of the TableView and I think what I've learned is:

If you need a UITableViewCell, use a UITableViewCell. If you need a UIView for the section headers, use a UIView for the section headers.

I've mixed the section headers with the TableViewCells just to re-use some code I had in there. Since categories can only extend one specific class I had to use delegation/provider methods/objects to re-use certain code. It may need more subclassing but is actually much safer.

In addition auto-scrolling to a position now works significantly better and the drawing artifacts are gone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜