简体   繁体   English

iOS修复TableView到底部像消息应用程序

[英]iOS Fix TableView To Bottom Like Messages App

So this is completely out of my area of (expertise?) so I figured I'd ask it and see if anyone more experienced could give me a yes or no answer. 所以这完全超出了我的专业领域?所以我想我会问它,看看是否有更多有经验的人可以给我一个是或否答案。

So, I'm using Appcelerator Titanium to build an app that has many tableviews. 所以,我正在使用Appcelerator Titanium构建一个包含许多tableviews的应用程序。 I am looking to build it so that some of the tableViews start at the bottom and I can scroll UP instead of scrolling DOWN to start, exactly the same way as the "Messages" app does on the iPhone. 我正在构建它,以便一些tableViews从底部开始,我可以向上滚动而不是向下滚动以启动,这与iPhone上的“Messages”应用程序完全相同。

The way it works is content loads in and it's automatically loaded in with the tableview fixed to the bottom, then you can scroll upwards to see older posts. 它的工作方式是内容加载,并自动加载,桌面视图固定在底部,然后您可以向上滚动以查看较旧的帖子。

I cannot find a way to do this in appcelerator other than create the tableview, load the data, then scroll it to the bottom (which obviously has that snapping). 除了创建tableview之外,我找不到在appcelerator中执行此操作的方法,加载数据,然后将其滚动到底部(显然有这样的捕捉)。 I can hide the tableview, scroll to bottom, then show the tableview, but again... not ideal. 我可以隐藏tableview,滚动到底部,然后显示tableview,但再次...不理想。

Now the question... Is it possible using the standard iOS SDK (Not appcelerator) to do set a table to fix to the bottom instead of the top? 现在问题 ...... 是否可以使用标准的iOS SDK(非appcelerator)来设置一个表来修复底部而不是顶部? If not, i'll have to find a work around somehow. 如果没有,我将不得不以某种方式找到一个工作。 If it is, I'd like to try to build it into a titanium module if at all possible... 如果是的话,我想尝试将它构建成钛模块,如果可能的话......

Anyways, thanks! 无论如何,谢谢! And hopefully this is a simple answer for some of you. 希望这对你们中的一些人来说是一个简单的答案。

Actually, it really is quite trivial. 实际上,这真的很微不足道。 Something like this would work just fine: 像这样的东西可以正常工作:

-(void)viewDidLoad {
   //place this at the bottom of your viewDidLoad method, or in any method that initially reloads the table
    NSIndexPath* ipath = [NSIndexPath indexPathForRow: myArray.count-1 inSection: 0];
    [tableView scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionBottom animated: NO]
}

I've tried to scroll in viewDidLoad, but after view controller appears, i can see the the begining of table on view appear. 我试图在viewDidLoad中滚动,但在视图控制器出现后,我可以看到视图中表格的开头出现。

I've found the better place for the initial scrolling. 我找到了最初滚动的好地方。

- (void) viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    NSInteger lastSectionIndex = MAX(0, [self.chatTableView numberOfSections] - 1);
    NSInteger lastRowIndex = MAX(0, [self.chatTableView numberOfRowsInSection:lastSectionIndex] - 1);
    NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex];
   [self.chatTableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}

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

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