我在情节提要中创建了一个带有四个标签的原型单元
然后在我的代码中,我为第一行、最后一行和其他行添加不同的背景图像。对于第一行,所有 4 个标签都被隐藏。
最初屏幕上显示的所有 5 行看起来都不错。但是当我向上滚动查看第 6 行时,它的行为就像第一行并且所有 4 个标签都被隐藏了。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Employee *currentEmployee=[Employee sharedData];
NSArray *tempArray =currentEmployee.leaveApproveDict;
static NSString *simpleTableIdentifier = @"approveLeaveCell";
approveLeaveCell *cell = [self.approveLeaveView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[approveLeaveCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if([tempArray count]!=0){
if(indexPath.row == 0){
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"h_t_top_bar.png"]];
cell.backgroundView = imgView;
cell.fromLabel.hidden=YES;
cell.toLabel.hidden=YES;
cell.typeLabel.hidden=YES;
cell.nameLabel.hidden=YES;
[cell setUserInteractionEnabled:NO];
}
else{
if(indexPath.row ==[tempArray count]){
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"h_t_bottom_bar.png"]];
cell.backgroundView = imgView;
}
else{
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"h_t_repeat_bar.png"]];
cell.backgroundView = imgView;
}
//assign the data
if(indexPath.row-1 < [tempArray count]){
NSDictionary *tempLeave= [currentEmployee.leaveApproveDict objectAtIndex:indexPath.row-1];
cell.toDateLabel.text=[self extractLeaveDate:(NSString*) [tempLeave objectForKey:@"leaveTo"]];
cell.fromDateLabel.text=[self extractLeaveDate:(NSString*)[tempLeave objectForKey:@"leaveFrom"]];
cell.leaveLabel.text=[tempLeave objectForKey:@"leaveType"];
cell.employeeNameLabel.text=[tempLeave objectForKey:@"requesterName"];
}
}
return cell;
}