zoukankan      html  css  js  c++  java
  • tableView 自动滚动到底部

    - (void)addData:(id)object{
       
       
        NSInteger count = self.dataArray.count;
       
       
       
        _index ++;
        NSString * str = [NSString stringWithFormat:@"当前第%zd行",_index];
        [self.dataArray addObject:str];
       
        if (count * 44.0f > self.tableView.height) {
            NSMutableArray *insert = [[NSMutableArray alloc] init];
            for (NSInteger index = count; index < count+1; index++) {
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
                [insert addObject:indexPath];
            }
            [self.tableView beginUpdates];
            [self.tableView insertRowsAtIndexPaths:insert withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView endUpdates];
            [self.tableView layoutIfNeeded];
           
            [self changeInsets:object];
            [self scrollToBottom];
        } else {
            [self.tableView reloadData];
        }
     
       
      
    }
     
     
    - (void)changeInsets:(id)object
    {
        CGFloat height = 0;
        height += 44.0f;
    //    for (NTESMessageModel *model in newModels) {
    //        height += 44.0f;
    //    }
        UIEdgeInsets insets = self.tableView.contentInset;
        CGFloat contentHeight = self.tableView.contentSize.height - insets.top;
        contentHeight += height;
        CGFloat top = contentHeight > self.tableView.height? 0 : self.tableView.height - contentHeight;
        insets.top = top;
       
    //    MyLog(@"tableViewHeight == %f",self.tableView.height);
    //    MyLog(@"top == %f",top);
       
        self.tableView.contentInset = insets;
    }
     
    - (void)scrollToBottom
    {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            CGFloat offset = self.tableView.contentSize.height - self.tableView.height;
            [self.tableView scrollRectToVisible:CGRectMake(0, offset, self.tableView.width, self.tableView.height) animated:YES];
        });
    }
  • 相关阅读:
    Hbase shell 常用命令
    HTable基本概念
    通过HBase Shell与HBase交互
    把Nutch爬虫部署到Hadoop集群上
    wso2esb安装及helloworld
    nDPI 的论文阅读和机制解析
    Ubuntu 编译出现 ISO C++ 2011 不支持的解决办法
    404 Note Found 队-课堂实战-项目UML设计
    nDPI的安装与测试
    精读 SBAR SDN flow-Based monitoring and Application Recognition
  • 原文地址:https://www.cnblogs.com/Jackie-subDai/p/9290099.html
Copyright © 2011-2022 走看看