[英]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.