简体   繁体   中英

UIImageView still visible after hiding/removing from superview

i hope you will find a solution for my problem, cause i don't have any ideas anymore.

I have a tableview, which has several cells. some cells have another view as subview on their contentView.

This additional view has 2 subviews: 1 UIImageView and 1 UILabel.

Now when i tap an UIButton the UIImageView should be hidden/removed and the UILabel changes it's textColor to white(black before).

The UILabel changes it's textColor but the UIImageView is still visible, even after removing the UIImageView from it's superview.

The Code looks like this.
_adsc_dot_view is the UIImageView
_adsc_text_label is the UILabel

- (void)mc_set_selected:(BOOL)selected {
    if (selected) {
        _adsc_dot_view.hidden = YES;
        _adsc_text_label.textColor = [UIColor whiteColor];
    }
    else {
        _adsc_dot_view.hidden = NO;
        _adsc_text_label.textColor = [UIColor blackColor];
    }
}

Some check you might find useful for this issue:

1) make sure you create once your UIImageView which referenced as _adsc_dot_view

2) do a debug, mark mc_set_selected with a breakpoint and in the log check the view hierarchy, whether you have the needed number of UIImageView and not more

po [[UIWindow keyWindow] recursiveDescription]

or check this advanced SO answer: I need to inspect the view hierarchy on an iPhone program

3) if you use Interface Builder make sure you have proper type (and not UIImage ) and proper reference

You are using UITableView and you add UIImageView and UILabel as a subview in UITableViewCell. So, I think you should reload UITabeView using [self.tableView reloadData]; or [YourTableName reloadData]; after your hide and show UIImageView method. Otherwise you should hide and show UIImageView using UIImageView tag or using UITableViewCell index path.

is the target device on iOS 7? If yes then do try to layoutsubviews of the cell. I had a similar issue where the cell wasn't refreshing on ios 7.

Just reload table view cell after Remove/Hide ImageView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM