Ghobs
Ghobs

Reputation: 859

UILabel in custom UITableViewCell moves up every time the table reloads

I've set up the positioning for my UILabels like so:

- (void) layoutSubviews {
    [super layoutSubviews];
    CGRect cvf = self.contentView.frame;
    self.imageView.frame = CGRectMake(0.0,
                                      0.0,
                                      cvf.size.height-1,
                                      cvf.size.height-1);
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;

    CGRect frame = CGRectMake(cvf.size.height + 5,
                              self.textLabel.frame.origin.y-10,
                              cvf.size.width - cvf.size.height - 2*1,
                              self.textLabel.frame.size.height);
    self.textLabel.frame = frame;

    frame = CGRectMake(cvf.size.height + 5,
                       self.detailTextLabel.frame.origin.y-8,
                       cvf.size.width - cvf.size.height - 2*1,
                       self.detailTextLabel.frame.size.height);
    self.detailTextLabel.frame = frame;

    frame = CGRectMake(cvf.size.height + 5,
                       self.bestMatchLabel.frame.origin.y-4,
                       cvf.size.width - cvf.size.height - 2*1,
                       self.bestMatchLabel.frame.size.height);
    self.bestMatchLabel.frame = frame;

}

For some reason, upon reloading the UITableView, bestMatchLabel moves up a few pixels, so that it looks like the below picture. Every time I reload it, it moves up more and more. I sense that there's something about the Y positioning thats causing it to relate its current position to its previous one. Am I correct? enter image description here

Upvotes: 0

Views: 105

Answers (1)

Feng Lin
Feng Lin

Reputation: 593

It is obvious the code :
self.textLabel.frame.origin.y-10, self.detailTextLabel.frame.origin.y-8 self.bestMatchLabel.frame.origin.y-4,
make the y change every load. You must set a fix y in every layout.

Upvotes: 1

Related Questions