UITableViewCell不会显示数据,直到向下滚动

时间:2016-10-12 07:53:06

标签: ios objective-c uitableview segue

我对JSON的{​​{1}}回复。

但是,UITableView在向下滚动之前不会显示数据。

请帮助我。如何解决?

抱歉我的英语不好。因为,我会说一点英语。

UITableView

2 个答案:

答案 0 :(得分:0)

这样做 -

- (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;
}

只需删除其他括号即可。 你正在做的事情是,如果在返回一个空单元格之后找不到单元格,并且在下一次滚动时,它将进入else块并且正在填充数据。 所以,只需删除其他括号。

答案 1 :(得分:0)

将以下代码替换为现有代码。

- (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;
}

此外,您还必须使用以下行重新加载tableview。每当您在globlOnDisplayEffect.arTableDataSelected

中添加内容时
[self.tableViewDetailList reloadData];