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

      

     

     

  • 相关阅读:
    Python日期与时间
    Python文章导航
    Python Tuple元组的操作说明
    Python List列表的操作说明
    Python数字类型及数学运算
    用Python实现一个简单的猜数字游戏
    Python基础语法
    设计模式的六大原则
    设计模式
    设计模式
  • 原文地址:https://www.cnblogs.com/likeIT/p/3476130.html
Copyright © 2011-2022 走看看