0

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];
    }
}
manuelwaldner
  • 551
  • 1
  • 5
  • 24
  • If you log _adsc_dot_view inside your button method, does it log correctly? – rdelmar Sep 18 '13 at 15:38
  • this can be a problem of reusable cells. I'm not sure, but the cells in tableView can be re-added, so your pointer `_adsc_dot_view` becomes pointing to `UIImageView` from cell which is not in the tableView anymore – medvedNick Sep 18 '13 at 15:53

4 Answers4

0

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

Community
  • 1
  • 1
nzs
  • 3,252
  • 17
  • 22
  • 1) is right. I accidentally called self instead of super in my init-function and as a result of this, the dot_view was added 2 times on my view but i only hid one of them then. Ty, sry for the late answer, but i was on vacation. – manuelwaldner Oct 07 '13 at 07:23
0

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.

Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38
0

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.

simply_me
  • 384
  • 1
  • 11
0

Just reload table view cell after Remove/Hide ImageView.

user1673099
  • 3,293
  • 7
  • 26
  • 57