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

时间:2012-08-19 05:02:21

标签: iphone ios scroll tableview

所以这完全超出了我的专业领域?所以我想我会问它,看看是否有更多有经验的人可以给我一个是或否答案。

所以,我正在使用Appcelerator Titanium构建一个包含很多tableviews的应用程序。我正在构建它,以便一些tableViews从底部开始,我可以向上滚动而不是向下滚动以启动,这与iPhone上的“Messages”应用程序完全相同。

它的工作方式是内容加载并自动加载,桌面视图固定在底部,然后您可以向上滚动以查看较旧的帖子。

除了创建tableview之外,我找不到在appcelerator中执行此操作的方法,加载数据,然后将其滚动到底部(显然有这样的捕捉)。我可以隐藏tableview,滚动到底部,然后显示tableview,但是再次......不理想。

现在问题...... 是否可以使用标准iOS SDK(非appcelerator)设置表格来修复底部而不是顶部?如果没有,我会有以某种方式寻找工作。如果是的话,我想尝试将其构建成钛模块,如果可能的话......

无论如何,谢谢!希望这对你们中的一些人来说是一个简单的答案。

2 个答案:

答案 0 :(得分:9)

实际上,这真的很微不足道。像这样的东西可以正常工作:

-(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]
}

答案 1 :(得分:1)

我试图在viewDidLoad中滚动,但在查看控制器出现后,我可以看到视图中表格的开头出现。

我找到了最初滚动的好地方。

- (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];
}