简体   繁体   English

从最后一个单元格启动UITableView

[英]Start UITableView from the last cell

I want to show the last cell first in a tableview like whatsapp did. 我想像whatsapp一样先在表格视图中显示最后一个单元格。 I don't want a scrolling animation. 我不要滚动动画。 Can anyone help me? 谁能帮我? Thanks 谢谢

[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

请注意:动画不是

You can do that by transforming the UITableView and any views you use in it, including UITableViewCell. 您可以通过转换UITableView及其中使用的任何视图(包括UITableViewCell)来实现。

First invert the tableview by setting the transform, 首先通过设置转换来反转表格视图,

tableView.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 0);

then in cellForRowAtIndexPath, you need to set the same transform to cell 然后在cellForRowAtIndexPath中,您需要将相同的转换设置为cell

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

     //This is important, since we are inverting the tableview , all subview must be inverted as well
    cell.transform = chatTableView.transform

    return cell
}

but this way you can load cells in recent first order, make sure all subviews is using the same transform as the tableView 但是通过这种方式,您可以按最近的第一顺序加载单元格,请确保所有子视图都使用与tableView相同的变换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM