zoukankan      html  css  js  c++  java
  • UITableView的插入、删除和滚动

    以下代码中dataArray是存储数据的数组,mainTableView是UITableView控件

    1.在UITableView的最底部插入

    -(void)loadTheLastCell
    
    {
    
        int lastIndex = [dataArray count]-1;
    
        if(lastIndex>=0)
    
        {
    
            NSIndexPath *path = [NSIndexPath indexPathForRow:lastIndex inSection:0];
    
            NSArray* tArray = [NSArray arrayWithObject:path];
    
            [mainTableView insertRowsAtIndexPaths:tArray withRowAnimation:UITableViewRowAnimationBottom];
       }
    
    }

    2.删除UITableView的数据

    -(void) deleteData
    {
         NSRange tRange = NSMakeRange(0,2);
            [dataArray removeObjectsInRange:tRange];
            
            NSIndexPath *path0 = [NSIndexPath indexPathForRow:0 inSection:0];
            NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0];
            
            NSArray* tArray = [NSArray arrayWithObjects:path0,path1,nil];
            [mainTableView deleteRowsAtIndexPaths:tArray withRowAnimation:UITableViewRowAnimationBottom];
    
    } 
          

    3.滚动到UITableView的最底部

    -(void)delayScrollToBottom
    {
        int lastIndex = [dataArray count]-1;
        if(lastIndex)
        {
            NSIndexPath *path = [NSIndexPath indexPathForRow:lastIndex inSection:0];
            [mainTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }
    }
    

      

     

     

  • 相关阅读:
    js写的ajax
    String根据、拆分
    Excel数据批量导入到数据库2
    Excel数据批量导入到数据库
    List去重复(不是最简单,但绝对是最易理解)
    struts中Cookie实现记住密码
    ==与equals的区别
    javascript实现登录验证码
    Javascript实现二级select联动
    javascript的假查询
  • 原文地址:https://www.cnblogs.com/likeIT/p/3476130.html
Copyright © 2011-2022 走看看