I have a UITableView with custom UITableViewCells. The contents of the cell are stored in a separate class that extends the UIView (I have 3 types of content that I switch, hiding and showing views, I used this approach because of the way I wanted to make the transition between cells). Therefore, let's say that I have one of the views visible and added to the contentView cell. This view contains text and some rectangles from UIViews. Everything is fine so far, but it’s strange when I touch the cell, the rectangles just disappear, the text remains the same. Do you know what could be the problem? I also tried adding a view to the backgroundView by doing the same.
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.active = NO; state = -1; // Touch is not working if the view has no bounds self.backgroundView = [[UIView alloc] init]; self.backgroundColor = [UIColor clearColor]; self.selectedBackgroundView = [[UIView alloc] init]; self.selectedBackgroundView.backgroundColor = [UIColor clearColor]; self.clipsToBounds = YES; self.contentView.clipsToBounds = YES; // Add empty view emptyView = [[View1 alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) andRadius:CELL_DOT_RADIUS]; emptyView.userInteractionEnabled = NO; [self.backgroundView addSubview:emptyView];
View:
- (id) initWithFrame:(CGRect)frame andRadius:(int)r { self = [super initWithFrame:frame]; radius = r; if (self) { int outerlineWeight = 1; timelineView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width/4, frame.size.height/2, 1, 1)]; [self addSubview:timelineView]; dotView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width/4-radius, frame.size.height/2-radius, radius*2, radius*2)]; dotView.layer.cornerRadius = radius; dotView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self addSubview:dotView]; UIView *n = [[UIView alloc] initWithFrame:CGRectMake(160, 0, 50, 20)]; n.backgroundColor = [UIColor redColor]; [self addSubview:n]; middleText = [[UILabel alloc] initWithFrame:dotView.frame]; middleText.font = [UIFont systemFontOfSize:12]; middleText.textColor = [UIColor grayColor]; middleText.backgroundColor = [UIColor clearColor]; middleText.textAlignment = NSTextAlignmentCenter; [self addSubview:middleText];
These are sources, so you can try it yourself if you want. As you can see, the orange rectangle disappears, but the text does not. For what I need to do, nothing should disappear, at best I want to change their colors. http://ge.tt/6wRBObD1/v/0?c
source share