ios - 如何在不使用Api的情况下在uitableview中进行分页?

标签 ios objective-c uitableview pagination nsdictionary

我正在做一个项目,我想在 uitableview 中使用分页而不使用 api。我有一个 nsdictionary 并且我将该字典保存在 nsarray 中,现在我希望在 ListView 类型中有 10、20、30 个数字以及我选择的数字rows 的数量将显示在 UI 中。 我在 uitableview

中完成了此操作
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSString *string1 = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string1];
    if(!cell)
    {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string1];
        UILabel *label1 = (UILabel*)[cell.contentView viewWithTag:401];
        CGFloat widthLabelHeader = CGRectGetWidth(orderTable.frame)/7;
        if(!label1)

        {

            label1 = [[UILabel alloc]init];
            label1.frame = CGRectMake(0, 0, widthLabelHeader, 45);
            label1.layer.borderWidth = 0.5;
            label1.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label1];
        }
               label1.textAlignment = NSTextAlignmentCenter;




        UILabel *label2 = (UILabel*)[cell.contentView viewWithTag:402];
        if(!label2)

        {

            label2 = [[UILabel alloc]init];
            label2.frame = CGRectMake(CGRectGetMaxX(label1.frame), 0, widthLabelHeader, 45);
            label2.layer.borderWidth = 0.5;
            label2.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label2];
        }
              label2.textAlignment = NSTextAlignmentCenter;


        UILabel *label3 = (UILabel*)[cell.contentView viewWithTag:403];
        if(!label3)

        {

            label3 = [[UILabel alloc]init];
            label3.frame = CGRectMake(CGRectGetMaxX(label2.frame), 0, widthLabelHeader, 45);
            label3.layer.borderWidth = 0.5;
            label3.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label3];
        }
        label3.textAlignment = NSTextAlignmentCenter;

        UILabel *label4 = (UILabel*)[cell.contentView viewWithTag:404];
        if(!label4)

        {
            label4 = [[UILabel alloc]init];
            label4.frame = CGRectMake(CGRectGetMaxX(label3.frame), 0, widthLabelHeader, 45);
            label4.layer.borderWidth = 0.5;
            label4.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label4];
        }
        label4.textAlignment = NSTextAlignmentCenter;

        UILabel *label5 = (UILabel*)[cell.contentView viewWithTag:405];
        if(!label5)

        {
            label5 = [[UILabel alloc]init];
            label5.frame = CGRectMake(CGRectGetMaxX(label4.frame), 0, widthLabelHeader, 45);
            label5.layer.borderWidth = 0.5;
            label5.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label5];
        }
        label5.textAlignment = NSTextAlignmentCenter;


        UILabel *label6 = (UILabel*)[cell.contentView viewWithTag:406];
        if(!label6)

        {
            label6 = [[UILabel alloc]init];
            label6.frame = CGRectMake(CGRectGetMaxX(label5.frame), 0, widthLabelHeader, 45);
            label6.layer.borderWidth = 0.5;
            label6.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label6];
        }
        label6.textAlignment = NSTextAlignmentCenter;


        UILabel *label7 = (UILabel*)[cell.contentView viewWithTag:407];
        if(!label7)

        {
            label7 = [[UILabel alloc]init];
            label7.frame = CGRectMake(CGRectGetMaxX(label6.frame), 0, widthLabelHeader, 45);
            label7.layer.borderWidth = 0.5;
            label7.font = [UIFont fontWithName:@"ChalkboardSE-Bold" size:14];
            [cell.contentView addSubview:label7];
        }
        label7.textAlignment = NSTextAlignmentCenter;




    dict1 = [array1 objectAtIndex:indexPath.row];
    if( dict1)
    {

        label1.text = [dict1 objectForKey:@"key1" ];
        label1.backgroundColor = [UIColor lightGrayColor];

        label2.text = [dict1 objectForKey:@"key2" ];
        label2.backgroundColor = [UIColor lightGrayColor];

        label3.text = [dict1 objectForKey:@"key3" ];
        label3.backgroundColor = [UIColor lightGrayColor];

        label4.text = [dict1 objectForKey:@"key4" ];
        label4.backgroundColor = [UIColor lightGrayColor];

        label5.text = [dict1 objectForKey:@"key5" ];
        label5.backgroundColor = [UIColor lightGrayColor];


        label6.text = [dict1 objectForKey:@"key6" ];
        label6.backgroundColor = [UIColor lightGrayColor];


        label7.text = [dict1 objectForKey:@"key7" ];
        label7.backgroundColor = [UIColor lightGrayColor];
    }}
    return cell;
    }

请帮助我如何做到这一点?

enter image description here

最佳答案

使用此方法是方法并调用 Api 并追加到表数据源中使用的相同数组中

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    BOOL endOfTable = (scrollView.contentOffset.y >= ((showListingArray.count * 60) - scrollView.frame.size.height)); // Here 40 is row height

    nextPage ++;
    NSString *nextPageStr = [NSString stringWithFormat:@"%d", nextPage];
    int totalpages = [[PaginnationDic objectForKey:@"totalPages"]intValue];

    if ( endOfTable && !scrollView.dragging && !scrollView.decelerating)
    {
        if (nextPage >= totalpages) {
                // NSLog(@"No More Page to load");
            return;
        }
        objPCDetailTableView.tableFooterView = footerView;
        NSDictionary *parametrs  = @{@"movieid":_movieID, @"page":nextPageStr, @"cityId":[Utility getCityID]};
        [self getMoviesDetailFromApi:parametrs];
        [(UIActivityIndicatorView *)[footerView viewWithTag:10] startAnimating];
    }

}

关于ios - 如何在不使用Api的情况下在uitableview中进行分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33213559/

相关文章:

ios - 将 NSArray 值转换为 int

ios - 将 UIImage 转换为 CIImage 时图像大小加倍

ios - 如何在uicollectionview中获取当前的cell.contentview。如何在 uicollectionview 单元格中添加 subview

ios - 滑动 UITableView 时调用什么函数

ios - 表格 View 单元格重新加载第一个单元格内容

ios - 使用 glReadPixels 读取纹理字节?

ios - 与 NSDateComponents 的时差

ios - 可选委托(delegate)方法上的 respondsToSelector

swift - 当 CustomCell 标签值更改时如何更新 UITableView?

iphone - 在 UITableView 中显示评论