In the interface designer, I have a very simple setup. The main view (which is a table cell view) has four sub-views, all siblings: UIImageView and three UILabels. I'm using UIImageView to display the background of the table row. I set it so that UIImageView is at the very back of the z-index tree and set its alpha to 0.2 to dim the image - and UILabel's are going over it.
If I set the image into the imageview at the design time in interface designer, then everything is fine, however if I set the image into the imageview at design time (I receive the actual image from the server), then the imageview alpha setting is ignored, the image is displayed at alpha = 1 and the uiimageview is displayed over all the labels. I even tried to use [parent sendSubviewToBack:imageView] but it didn't help.
What am I missing? Here's my whole code for displaying the table row.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"OOItemInfoCell" owner:self options:nil] lastObject];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
OOXMLNode *infoNode = [searchItemList objectAtIndex:indexPath.row];
[(UILabel *)[cell viewWithTag:2] setText:[itemNode elementNodeWithKey:@"title"].value];
[(UILabel *)[cell viewWithTag:3] setText:[itemNode elementNodeWithKey:@"intro"].value];
[(UILabel *)[cell viewWithTag:4] setText:[NSString stringWithFormat:kThemeAge,
[itemNode elementNodeWithKey:@"theme"].value,
[itemNode elementNodeWithKey:@"age"].value]];
UIImageView *bgview = (UIImageView *)[cell viewWithTag:0];
[bgview setImage:[itemNode imageFromKey:@"background"]];
[cell sendSubviewToBack:bgview];
return cell;
}
Ok, this was pretty stupid of me... I had the tag of the UIImageView set to 0 and then was using
viewWithTag:0to find that view. Yet, the parent view also had tag 0, so instead of my background UIImageView, the entire cell was being set to the image (I wouldn't think that a table cell view would respond tosetImage- but it did.I now changed the tag on UIImageView to 5 - and everything is hunky-dory.