The cell of tavbview quickly slides into a blank

36 Views Asked by At

A tabview pull up, load the new data, and then quickly pull up, the above cell disappears and becomes blank,I guess because the refresh time, the data is not with the new This is the main code:

@interface DYBOrdersViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSMutableArray * currentArr;

@property(nonatomic,strong)NSArray * dataArr;

@property(nonatomic,strong)UITableView * mainTab;

@property(nonatomic,strong)UIRefreshControl * refreshC;

@property(nonatomic,assign)BOOL isPull;

@property(nonatomic,assign)CGFloat cellheight;

@end

static NSString * orderID = @"orderID";

@implementation DYBOrdersViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSMutableArray * mutarr0 = [NSMutableArray arrayWithObjects:@"全部",@"全部",@"全部",@"完成",@"全部", nil];

    NSMutableArray * mutarr1 = [NSMutableArray arrayWithObjects:@"待取件",@"待取件",@"待取件",@"待取件", nil];

    NSMutableArray * mutarr2 = [NSMutableArray arrayWithObjects:@"未完成",@"未完成",@"未完成", nil];

    NSMutableArray * mutarr3 = [NSMutableArray arrayWithObjects:@"已完成",@"已完成", nil];

    NSMutableArray * mutarr4 = [NSMutableArray arrayWithObjects:@"已取消", nil];

    self.dataArr = @[mutarr0,mutarr1,mutarr2,mutarr3,mutarr4];

    self.currentArr = self.dataArr[0];

    [self setUI];

    self.automaticallyAdjustsScrollViewInsets = NO;
}

// 设置界面
-(void)setUI{
    UIRefreshControl * refreshC = [[UIRefreshControl alloc]initWithFrame:self.navBar.bounds];

    self.refreshC = refreshC;

    [refreshC beginRefreshing];
    [refreshC addTarget:self action:@selector(loadData) forControlEvents:UIControlEventValueChanged];

    NSArray * segArr = @[@"全部",@"待取件",@"待收货",@"待评价",@"已取消"];

    UISegmentedControl * segC = [[UISegmentedControl alloc]initWithItems:segArr];

    segC.frame = CGRectMake(0,64, self.view.frame.size.width,40);

    segC.tintColor = [UIColor sun_colorWithHex:0x0082f5];

//实现添加的事件

    [segC addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];

// 创建刷新界面

    UITableView * tabV = [[UITableView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(segC.frame), [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - CGRectGetMaxY(segC.frame)-self.tabBarController.tabBar.frame.size.height) style:UITableViewStylePlain];

    tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
    tabV.showsVerticalScrollIndicator = NO;
    tabV.delegate = self;
    tabV.dataSource = self;

    self.mainTab = tabV;

    [tabV registerClass:[DYBOrdersViewCell class] forCellReuseIdentifier:orderID];

    [tabV addSubview:self.refreshC];

    [self.view addSubview:tabV];

    [self.view addSubview:segC];
}
 // Refresh data method

-(void)loadData{

    [self.refreshC endRefreshing];

    [self.currentArr addObject:@"新数据"];

    self.isPull = NO;

    [self.mainTab reloadData];

}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 100;
}
//点击不同分段就会有不同的事件进行相应

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSLog(@"%lu",(unsigned long)self.currentArr.count);
    return self.currentArr.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    DYBOrdersViewCell * cell  = [tableView dequeueReusableCellWithIdentifier:orderID forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.textLabel.text = self.currentArr[indexPath.row];

    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    DYBOrderdetailController * VC = [[DYBOrderdetailController alloc]init];
    VC.title = @"订单详情";
    VC.view.backgroundColor = [UIColor whiteColor];

    [self.navigationController pushViewController:VC animated:YES];

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    // 将要显示的最后一组
    NSInteger section  = indexPath.section;
    // 所有cell数
    NSInteger count = [tableView numberOfRowsInSection:section];

    //将要显示的row数量
    NSInteger row = indexPath.row ;

    if (section <0 || row <0) {
        return;
    }

    // 如果是最后一行最后一个cell 数据刷新
    if (row == count -1 && !self.isPull) {
        NSLog(@"要刷新了");
        self.isPull = YES;
        [self loadData];
    }

}
0

There are 0 best solutions below