Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm having a problem with my UITableView. A UIView in the cells (the light grey background) seems to fill the cell for no apparent reason when scrolling.

Here's how it should look:

Here's how it looks once you've scrolled up and down: enter image description here

Here's my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    CustomTableViewCell *cell = (CustomTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    [self.tableView registerNib:[UINib nibWithNibName:@"CustomTableViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];

    NSArray *post = [posts objectAtIndex:[indexPath row]];
    NSString *name = [post objectAtIndex:0];
    NSString *school = [post objectAtIndex:1];
    NSString *profilePicture = [post objectAtIndex:2];
    NSString *status = [post objectAtIndex:3];

    [cell.name setText:name];
    [cell.school setText:school];
    [cell.status setText:status];

    #define kMaxHeight 300.f
    cell.status.contentSize = [cell.status.text sizeWithFont:[UIFont systemFontOfSize:14]
                                           constrainedToSize:CGSizeMake(295, kMaxHeight)
                                               lineBreakMode:UIViewAutoresizingFlexibleHeight];

    [cell.status setFrame:CGRectMake(cell.status.frame.origin.x, cell.status.frame.origin.y, 295, cell.status.contentSize.height + 25)];

    float height = 60 + cell.status.contentSize.height;

    [cell.backgroundView setFrame:CGRectMake(cell.backgroundView.frame.origin.x, cell.backgroundView.frame.origin.y, cell.backgroundView.frame.size.width, height - 10)];

    [cell.backgroundView clipsToBounds];
    [cell clipsToBounds];

    return cell;

}

What am I doing wrong?

share|improve this question
2  
"What am I doing wrong?" Manipulating frame manually instead of using AutoLayout on iOS7. – Guillaume Algis 14 hours ago
Wait - I don't understand. How should I use AutoLayout on iOS 7? – JamesAnderson585 12 hours ago
How: AutoLayout Introduction. Why: Because it already was a best practice in iOS 6, and because with XCode 5 you don't have any good excuse anymore ;) – Guillaume Algis 11 hours ago
@GuillaumeAlgis: What is wrong in setting the frame manually? – Lithu T.V 10 hours ago
@JamesAnderson585 is the autoresizing of the view is set properly in the nib? – Lithu T.V 10 hours ago

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.