简体   繁体   English

UITableViewCell在向下滚动之前不会显示数据

[英]UITableViewCell don't show up data until scroll down

My JSON response to UITableView . 我对UITableView JSON响应。

But, UITableView isn't show up data until scroll down. 但是,直到向下滚动, UITableView才会显示数据。

Please help me.How to resolve it? 请帮助我。如何解决?

Sorry for my bad English language. 对不起,我的英语不好。 Because, I can speak English a little bit. 因为,我会说一点英语。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    globlOnDisplayEffect = [GlobalVariable sharedInstance];
    globlOnDisplayEffect.arTableDataSelectedWhereHouse = [[NSArray alloc] init];

}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

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

    return [globlOnDisplayEffect.arTableDataSelected count]>0 ?[globlOnDisplayEffect.arTableDataSelected count]:1;

}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"DisplayEffectQtyViewCell";
    DisplayEffectQtyViewCell *cell = [self.tableViewDetailList dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DisplayEffectQtyViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

    } 
    if (globlOnDisplayEffect.arTableDataSelected) {
        NSMutableArray *myMutbleArray = [[NSMutableArray alloc] init];
        [myMutbleArray addObject:globlOnDisplayEffect.arTableDataSelected];
        if (myMutbleArray)
        {
                NSDictionary *myDic = [globlOnDisplayEffect.arTableDataSelected objectAtIndex:indexPath.row];
                NSDictionary *cont = [myDic objectForKey:@"DataList_SPI_DetailF10"];
                NSString *f10_cmpt = [self getString:[cont objectForKey:@"f10_cmpt"]];
                NSString *f10_dt = [self getString:[cont objectForKey:@"f10_dt"]];
                NSString *f10_item = [self getString:[cont objectForKey:@"f10_item"]];
                NSString *f10_lot = [self getString:[cont objectForKey:@"f10_lot"]];
                NSString *f10_model = [self getString:[cont objectForKey:@"f10_model"]];
                NSString *f10_of = [self getString:[cont objectForKey:@"f10_of"]];
                NSString *f10_semi = [self getString:[cont objectForKey:@"f10_semi"]];
                NSString *f10_tm = [self getString:[cont objectForKey:@"f10_tm"]];
                NSString *f10_uncmp = [self getString:[cont objectForKey:@"f10_uncmp"]];
               [cell setf10_cmpt:f10_cmpt setf10_dt:f10_dt setf10_item:f10_item setf10_lot:f10_lot setf10_model:f10_model setf10_of:f10_of setf10_semi:f10_semi setf10_tm:f10_tm setf10_uncmp:f10_uncmp];
         }
    }

    return cell;
}

Do this -- 做这个 -

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"DisplayEffectQtyViewCell";
    DisplayEffectQtyViewCell *cell = [self.tableViewDetailList dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DisplayEffectQtyViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

    }  if (globlOnDisplayEffect.arTableDataSelected) {
        NSMutableArray *myMutbleArray = [[NSMutableArray alloc] init];
        [myMutbleArray addObject:globlOnDisplayEffect.arTableDataSelected];
         if (myMutbleArray)
        {
            NSDictionary *myDic = [globlOnDisplayEffect.arTableDataSelected objectAtIndex:indexPath.row];
            NSDictionary *cont = [myDic objectForKey:@"DataList_SPI_DetailF10"];
            NSString *f10_cmpt = [self getString:[cont objectForKey:@"f10_cmpt"]];
            NSString *f10_dt = [self getString:[cont objectForKey:@"f10_dt"]];
            NSString *f10_item = [self getString:[cont objectForKey:@"f10_item"]];
            NSString *f10_lot = [self getString:[cont objectForKey:@"f10_lot"]];
            NSString *f10_model = [self getString:[cont objectForKey:@"f10_model"]];
            NSString *f10_of = [self getString:[cont objectForKey:@"f10_of"]];
            NSString *f10_semi = [self getString:[cont objectForKey:@"f10_semi"]];
            NSString *f10_tm = [self getString:[cont objectForKey:@"f10_tm"]];
            NSString *f10_uncmp = [self getString:[cont objectForKey:@"f10_uncmp"]];

            [cell setf10_cmpt:f10_cmpt setf10_dt:f10_dt setf10_item:f10_item setf10_lot:f10_lot setf10_model:f10_model setf10_of:f10_of setf10_semi:f10_semi setf10_tm:f10_tm setf10_uncmp:f10_uncmp];
        }
    }
    return cell;
}

Just remove the else brackets. 只需卸下else括号即可。 The thing you were doing is if cell is not found after dequeue you are returning an empty cell, and in the next time when scrolling, it is going inside the else block and it is being filled up with data. 您正在做的事情是,如果在出队后未找到单元,则您将返回一个空单元,并且在下一次滚动时,该单元将进入else块内部,并被数据填充。 So, just remove the else brackets. 因此,只需移除else括号即可。

Replace the following code with the existing one. 将以下代码替换为现有代码。

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"DisplayEffectQtyViewCell";
    DisplayEffectQtyViewCell *cell = [self.tableViewDetailList dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DisplayEffectQtyViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

    } 
    //check whether the globlOnDisplayEffect.arTableDataSelected is empty
    if(globlOnDisplayEffect.arTableDataSelected  != nil && [globlOnDisplayEffect.arTableDataSelected count] > 0){
                NSDictionary *myDic = [globlOnDisplayEffect.arTableDataSelected objectAtIndex:indexPath.row];
                NSDictionary *cont = [myDic objectForKey:@"DataList_SPI_DetailF10"];
                NSString *f10_cmpt = [self getString:[cont objectForKey:@"f10_cmpt"]];
                NSString *f10_dt = [self getString:[cont objectForKey:@"f10_dt"]];
                NSString *f10_item = [self getString:[cont objectForKey:@"f10_item"]];
                NSString *f10_lot = [self getString:[cont objectForKey:@"f10_lot"]];
                NSString *f10_model = [self getString:[cont objectForKey:@"f10_model"]];
                NSString *f10_of = [self getString:[cont objectForKey:@"f10_of"]];
                NSString *f10_semi = [self getString:[cont objectForKey:@"f10_semi"]];
                NSString *f10_tm = [self getString:[cont objectForKey:@"f10_tm"]];
                NSString *f10_uncmp = [self getString:[cont objectForKey:@"f10_uncmp"]];
               [cell setf10_cmpt:f10_cmpt setf10_dt:f10_dt setf10_item:f10_item setf10_lot:f10_lot setf10_model:f10_model setf10_of:f10_of setf10_semi:f10_semi setf10_tm:f10_tm setf10_uncmp:f10_uncmp];
    }
    return cell;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [globlOnDisplayEffect.arTableDataSelected count];
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

Also you have to reload the tableview with the following line. 另外,您还必须使用以下行重新加载tableview。 Whenever you Added a content inside the globlOnDisplayEffect.arTableDataSelected 每当您在globlOnDisplayEffect.arTableDataSelected内部添加内容时

[self.tableViewDetailList reloadData];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 滚动后,UITableview单元格不会显示 - UITableview cells don't show up until you scroll 在滚动之前,UITableViewCell按钮不会显示选中或取消选中状态 - UITableViewCell button doesn't show selected or deselected state until scroll UITableview 单元格在您滚动之前不会显示。 也在主队列中 - UITableview cells don't show up until you scroll. also with in main queue 我的uitableviewCell的内容没有显示? - the content of my uitableviewCell doen't show up? 添加到UINavigationController的按钮在导航到下一页之后才会显示 - Buttons added to UINavigationController don't show up until after navigating to next page 向下/向上滚动时淡入/显示UIButton - fade/show UIButton when scroll down/up 向上滚动时显示 header 的 uitableview,向下滚动时隐藏 header 的 uitableview - Show header of uitableview on scroll up and hide header of uitableview on scroll down Swift:向上滚动时显示搜索栏,向下滚动时隐藏它 - Swift : show searchbar when scroll up and hide it when scroll down 迅速:上下滚动时,UITableViewCell数据重叠 - swift: UITableViewCell data overlapped when scrolling down and up 直到单元格滚动离开屏幕,UITableViewCell中的UIButton才会显示textLabel更改 - UIButtons in UITableViewCell do not show textLabel changes until cells scroll off screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM