首页 > 技术文章 > uitableview滚动到最后一行

Camier-myNiuer 2015-01-06 17:37 原文

本文转载至 http://mrjeye.iteye.com/blog/1278521

 

- (void)scrollTableToFoot:(BOOL)animated

{

    NSInteger s = [self.tableView numberOfSections];

    if (s<1) return;

    NSInteger r = [self.tableView numberOfRowsInSection:s-1];

    if (r<1) return;

    

    NSIndexPath *ip = [NSIndexPath indexPathForRow:r-1 inSection:s-1];

    

    [self.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:animated];

 

}

 

############

 

  1. 可在viewDidAppear中实现加入 [tablvew setContentOffset:CGPointMake(0,480) animated:YES];  
  2. 在tableView内添加一个searchbar,一起滚动;开始时隐藏headerView(即让tableView向上滚动headerView的高度:默认44)  
  3. UISearchBar *mySearchBar = [[UISearchBar alloc] init];  
  4. [mySearchBar sizeToFit];  
  5.   
  6. tableView.tableHeaderView = mySearchBar;  
  7. //UITableView开始滚动到的位置(这样一开始headerView是不显示的)  
  8. [tableView setContentOffset:CGPointMake(0.0, 44.0) animated:NO];  

 

推荐阅读