Note that there are some explanatory texts on larger screens.

plurals
  1. POTableView Content Height Keeps growing
    primarykey
    data
    text
    <p>I have a dynamic UITableView. It will insert or delete rows when button clicked.</p> <pre><code>-(IBAction)foldingClicked:(id)sender { self.isInfoFolded = !self.isInfoFolded; if( self.isInfoFolded) { //self.mainTable remove rows }else { //self.mainTable insert rows } } </code></pre> <p>It looks fine when running. But after clicking the button a few times, my table view's contentView grows a lot in height and the tableView could scroll to a very far place that no content is on screen at all.</p> <p>How could I keep my tableView's content height as much as actual needed?</p> <p>I just now try to log contentSize.height everytime when the button is clicked. It appears that each time it grows 123 pixels or shrink 95 pixels. I still don't have any clue how this 28 pixels keeps staying in content size. There must be something wrong with my code. But where should I possibly check? </p> <p>Edited - I checked my coding according to @Stavash's recommendation.</p> <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if( indexPath.section == SECTION_STORE ) { if( self.store) { return self.storeView.frame.size.height; }else { return self.noStoreView.frame.size.height; } } else { return 0; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if( indexPath.section == SECTION_STORE) { if( self.store) { cellIdtifier = @"StoreCell"; }else { cellIdtifier = @"No-StoreCell"; } UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdtifier]; if(!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdtifier]; if( self.store) { [cell.contentView addSubview: self.storeView]; }else { [cell.contentView addSubview: self.noStoreView]; } } return cell; } else { return nil; } } </code></pre> <p>The <code>storeView</code> and <code>noStoreView</code> are initiated from nib file with different height and are both flexible in height. It seems because the cell view grows or shrinks when button clicked, they will grow too because of flexible height. My issue is finally fixed by making these two views fix height. :) :) :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload