How to Start UITableView on the Last Cell?

前端 未结 8 1273
囚心锁ツ
囚心锁ツ 2020-11-30 01:43

In Apple\'s Messages app, when you click a correspondent\'s name and switch to the table view of the conversation (with balloons for each message), the table appears scrolle

8条回答
  •  猫巷女王i
    2020-11-30 02:31

    You can call -scrollToRowAtIndexPath:atScrollPosition:animated within the -viewWillAppear: method of your TableViewController.

    atScrollPosition: allows you to set where you want your cell for rowAtIndexPath to appear. There are four options:

    UITableViewScrollPositionTop - puts your cell right at the top of the view

    UITableViewScrollPositionMiddle - centers your cell in the view

    UITableViewScrollPositionBottom - puts your cell at the bottom

    UITableViewScrollPositionNone - Using this setting will position in the cell in user view with minimum scrolling/movement.

    The behavior is different in three scenarios :-

    If the cell is already in view, it does nothing.

    If the cell is above the current view, it scrolls the cell to the top of the view.

    If the cell is beneath the current view, it scrolls the cell to the bottom of the view.

提交回复
热议问题