zoukankan      html  css  js  c++  java
  • IOS

    Phone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10条,table底部有一察看更多选项,点击察看更多查看解析的剩余数据。基本上就是数据源里先只放10条, 点击最后一个cell时, 添加更多的数据到数据源中. 比如:

    数据源是个array:

    NSMutableArray *items; 

    ViewController的这个方法返回数据条数: +1是为了显示"加载更多"的那个cell

    1
    2
    3
    4
    5
    - (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section 
    {  
        int count = [items count];  
        return  count + 1;  
    }

    这个方法定制cell的显示, 尤其是"加载更多"的那个cell:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    - (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {  
        if([indexPath row] == ([items count])) 
        {  
            //创建loadMoreCell  
            return loadMoreCell;  
        }  
        //create your data cell  
        return cell;  
    }

    还要处理"加载更多"的那个cell的选择事件,触发一个方法来加载更多数据到列表

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    - (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {  
           
        if (indexPath.row == [items count]) 
    {  
            [loadMoreCell setDisplayText:@"loading more ..."];  
            [loadMoreCell setAnimating:YES];  
            [self performSelectorInBackgroundselector(loadMore) withObject:nil];  
            //[loadMoreCell setHighlighted:NO];  
            [tableView deselectRowAtIndexPath:indexPath animated:YES];  
            return;  
        }  
        //其他cell的事件  
    }

    加载数据的方法:

    1
    2
    3
    4
    5
    6
    -(void)loadMore  
    {  
        NSMutableArray *more;   
        //加载你的数据  
        [self performSelectorOnMainThreadselector(appendTableWith withObject:more waitUntilDone:NO];  
    }

    添加数据到列表:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    -(void) appendTableWithNSMutableArray *)data  
    {  
        for (int i=0;i<[data count];i++) 
        {  
            [items addObject:[data objectAtIndex:i]];  
        }  
        NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10];  
        for (int ind = 0; ind < [data count]; ind++) 
        
            NSIndexPath *newPath =  [NSIndexPath indexPathForRow:[items indexOfObject:[data objectAtIndex:ind]] inSection:0];   
            [insertIndexPaths addObject:newPath];  
        }  
        [self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];  
    }

     

  • 相关阅读:
    04-struts2框架中获取servlet api及Result结果类型
    03-Action类的创建方式及访问
    一位资深程序员大牛给予Java初学者的学习建议(转)
    C++中数组指针
    Ubuntu 开机出现 grub rescue> 终端模式修复方法
    windows和linux双系统下扩容方法
    C 字符串处理
    C++类中变量定义初始化总结
    python创建xml
    OpenBlas compile centOS6.7 ./kernel/x86_64/dgemm_kernel_4x4_haswell.S:2548: Error: no such instruction: `vpermpd $
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/3614201.html
Copyright © 2011-2022 走看看