UITableView有多个标签和一个imageview。此视图显示某些信息。 加载此视图时,将显示除图像之外的所有内容。 ImageView最初不会显示图像,相反,我要向上/向下滚动表格,然后它会出现。
这里的代码,
for (id v in cell.contentView.subviews) {
UIView *realV = (UIView *) v;
[realV removeFromSuperview];
}
当我向他询问这个问题时,我的朋友建议。他说这会解决它。我使用的原始代码没有其他部分。完整代码如下。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"cellid";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
if (tableView==tableForControls)
{
switch (indexPath.row)
{
case 0:
{
UIImageView *frameImageView = [[UIImageView alloc]initWithFrame:CGRectMake(108, 7, 94, 104)];
[frameImageView setImage:[UIImage imageNamed:@"2 Page Baby Photo Frame.png"]];
imageViewForChildImage = [[UIImageView alloc]initWithFrame:CGRectMake(90, 12, 130, 92)];
imageViewForChildImage.tag = 123;//childImage
[imageViewForChildImage setImage:[UIImage imageNamed:@"childImage.png"]];
imageViewForChildImage.contentMode=UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:imageViewForChildImage];
[cell.contentView addSubview:frameImageView];
[cell.textLabel setHidden:TRUE];
break;
}
case 5:
{//102.123,162
UITextView *notesTxtViewObject = [[UITextView alloc]initWithFrame:CGRectMake(5, 15, 300, 120)];
[notesTxtViewObject setTextColor:cell.detailTextLabel.textColor];
notesTxtViewObject.tag = 456;
notesTxtViewObject.layer.borderWidth = 1.0f;
notesTxtViewObject.layer.borderColor = [UIColor lightGrayColor].CGColor;
notesTxtViewObject.layer.cornerRadius = 3.0f;
notesTxtViewObject.delegate = self;
[notesTxtViewObject setFont:[UIFont fontWithName:@"Trebuchet MS" size:14]];
notesTxtViewObject.inputAccessoryView = keyBoardBar;
[cell.contentView addSubview:notesTxtViewObject];
UILabel *charLengthLabel = [[UILabel alloc]initWithFrame:CGRectMake(160, 145, 145, 40)];
[charLengthLabel setFont:[UIFont fontWithName:@"Trebuchet MS" size:14]];
charLengthLabel.tag = 789;
charLengthLabel.textAlignment = NSTextAlignmentCenter;
[cell.contentView addSubview:charLengthLabel];
[cell.textLabel setHidden:TRUE];
break;
}
default:
break;
}
}
else
{
}
}
if (tableView==tableForControls)
{
cell.textLabel.text = [titleArray objectAtIndex:indexPath.row];
UIImageView *childImage =(UIImageView*)[cell.contentView viewWithTag:123];
UITextView *notesTextViewObj = (UITextView *)[cell.contentView viewWithTag:456];
UILabel *charecterLenght = (UILabel *)[cell.contentView viewWithTag:789];
switch (indexPath.row)
{
case 0:
childImage.image = [UIImage imageWithData:[valueDict objectForKey:cell.textLabel.text]];
break;
case 5:
notesTextViewObj.text = [valueDict objectForKey:cell.textLabel.text];
break;
default:
cell.detailTextLabel.text = [valueDict objectForKey:cell.textLabel.text];
break;
}
charecterLenght.text = notesString;
[cell.textLabel setFont:[UIFont fontWithName:@"Trebuchet MS" size:16]];
[cell.detailTextLabel setFont:[UIFont fontWithName:@"Trebuchet MS" size:14]];
[cell.textLabel setTextColor:[UIColor colorWithRed:254/255.0f green:218/255.0f blue:87/255.0f alpha:1]];
}
else if (tableView==tableForChildList)
{
ChildMaster *childMaster = [childCollectionArray objectAtIndex:indexPath.row];
cell.textLabel.text = childMaster.name;
[cell.textLabel setFont:[UIFont fontWithName:@"Trebuchet MS" size:14]];
}
else
{
cell.imageView.image=[UIImage imageNamed:[arrayForImages objectAtIndex:indexPath.row]];
}
cell.selectionStyle = UITableViewCellEditingStyleNone;
return cell;
}