TableView,加载更多

来源:互联网 发布:2017网络效应题库 编辑:程序博客网 时间:2024/05/19 03:23

把tableveiw 的footerview 在footer上添加加载更多 的button 

UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeCustom];

    [btnsetFrame:CGRectMake(0, 0, 320, 40)];      

    [btn setTitle:@"更多精彩" forState:UIControlStateNormal];

    [btn setTitleColor:[UIColorredColor]forState:UIControlStateNormal];

    

    [btn addTarget:selfaction:@selector(Loadmore)forControlEvents:UIControlEventTouchUpInside];

    self.Table.tableFooterView=btn;


-(void)Loadmore

{

    NSMutableArray *mutableArray=[[NSMutableArrayalloc]initWithCapacity:1];

    for(int i=[self.dataSourcecount];i<[self.dataSourcecount]+7;i++)

    {

        NSIndexPath *indexPath=[NSIndexPathindexPathForRow:iinSection:0];

        [mutableArrayaddObject:indexPath];

    }

//记住这里要增加的数据是需要和前面声明的tabeview 初次加载的数据是一样的哦

   for (int i=0; i<7; i++)

    {

        NSString *str=[NSStringstringWithFormat:@"%d",i];

        

        [self.dataSourceaddObject:str];

    }

    [self.tableViewinsertRowsAtIndexPaths:mutableArraywithRowAnimation:UITableViewRowAnimationFade];

    

}