Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting row height to 0 in UITableView, but cell text still shows up overlapping

I currently have my row heights set up like so:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == self.expandedSection || indexPath.row <= 3) {
        return 65;
    }

    return 0;
}

I essentially only want the first 4 rows to be visible by default, unless the section is in expanded form, in which case all rows are visible. I'm doing this by setting the row heights of the first 4 to 65, and the rest to 0. The rows and their respective images don't show up, however the cell.textLabel and cell.detailTextLabels are, leading to them looking like the picture below.

How can I disable both of those so that they don't show up at all for any rows past row 4?

enter image description here

like image 420
Ghobs Avatar asked Nov 21 '14 09:11

Ghobs


2 Answers

Should add as answer:

be sure to have Clip to bounds property set to YES either on nib file or programmatically as cell.clipToBounds=YES

like image 82
htafoya Avatar answered Oct 06 '22 21:10

htafoya


add this code in your cellForRowAtIndexPath

if (indexPath.section == self.expandedSection || indexPath.row <= 3) {
       Cell.hidden = NO; 
    }
else{
    Cell.hidden = YES;
}
like image 34
Mihir Oza Avatar answered Oct 06 '22 21:10

Mihir Oza