有一个随机发生的奇怪问题。滚动并返回单元格时,单元格将处于未填充状态。请看下面的一些图片,这是我的tableview代表:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
NSLog(@"%lu",(unsigned long)[datas count]);
return [datas count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//NSLog(@"%@",[sects objectAtIndex:section]);
return [self cleanText:[sects objectAtIndex:section]];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//return [datas count];
//NSLog(@"%ld",(long)[[datas objectAtIndex:section] count]);
return (NSInteger)[[datas objectAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
HHCellPlaceOrder *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//NSLog(@"Method Called");
//Get NSDictionary for Cell
NSDictionary *dict = [[datas objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.lblSku.text = [dict objectForKey:@"itemnumber"];
cell.lblDescription.text = [dict objectForKey:@"description"];
cell.lblSize.text = [dict objectForKey:@"itemsize"];
cell.lblUnitCost.text = [dict objectForKey:@"netcost"];
cell.lblQtyOnHand.text = [dict objectForKey:@"inventory"];
cell.lblCost.text = [dict objectForKey:@"costfield"];
cell.txtQty.text = [dict objectForKey:@"qtyfield"];
if ([cell.txtQty.text isEqualToString:@"0"] == NO) {
cell.cellBG.backgroundColor = [UIColor lightGrayColor];
//cell.lblUPC.backgroundColor = [UIColor lightGrayColor];
} else{
cell.cellBG.backgroundColor = [UIColor whiteColor];
//cell.lblUPC.backgroundColor = [UIColor whiteColor];
}
CGRect frame = cell.cellBG.frame;
if ([[dict objectForKey:@"showBar"] isEqualToString:@"1"]){
cell.img_bar.hidden = NO;
cell.lblUPC.hidden = NO;
cell.lblUPC.backgroundColor = [UIColor whiteColor];
//Bar Code...
NKDUPCABarcode *bar = [NKDUPCABarcode alloc];
bar = [bar initWithContent:[dict objectForKey:@"UPC"]];
UIImage *i = [UIImage imageFromBarcode:bar];
cell.img_bar.image = i;
cell.img_bar.backgroundColor = [UIColor whiteColor];
cell.lblUPC.text = [dict objectForKey:@"UPC"];
frame.size.height = 158;
} else{
cell.img_bar.hidden = YES;
cell.lblUPC.hidden = YES;
cell.img_bar.image = nil;
cell.lblUPC.text = @"";
frame.size.height = 55;
}
cell.cellBG.frame = frame;
return cell;
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dict = [[datas objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
if ([[dict objectForKey:@"showBar"] isEqualToString:@"1"]){
return 158.0f;
} else{
return 55.0f;
}
}
图片 - 链接,因为我无法发布图片:(
普通视图 - https://dl.dropboxusercontent.com/u/14627145/normallook.jpg
在一些滚动示例之后 - https://dl.dropboxusercontent.com/u/14627145/WeirdCell1.jpg
我感谢任何帮助! :d