Keep uitableview static when inserting rows at the top

后端 未结 18 2114
名媛妹妹
名媛妹妹 2020-11-29 16:12

I have a tableView that I\'m inserting rows into at the top.

Whilst I\'m doing this I want the current view to stay completely still, so the rows only appear if you

18条回答
  •  孤街浪徒
    2020-11-29 16:37

    How are you adding the rows to the table?

    If you're changing the data source and then calling reloadData, that may result in the table being scrolled to the top again.

    However, if you use the beginUpdates, insertRowsAtIndexPaths:withRowAnimation:, endUpdates methods, you should be able to insert rows without having to call reloadData thus keeping the table in its original position.

    Don't forget to modify your data source before calling endUpdates or else you'll end up with an internal inconsistency exception.

提交回复
热议问题