Note that there are some explanatory texts on larger screens.

plurals
  1. POFrame of header view changed forever after deletion of UITableView's section
    primarykey
    data
    text
    <p>I'm reusing headers, keeping them in dictionary where section number is key and header view is value. </p> <p>After I animated deleted one section and reload another one, header views of only these sections "disappeared". After some searching, I found that frames of these header view was changed. <code>Frame.X</code> of header view from section that was deleted with <code>UITableViewRowAnimationRight</code> shifter to right by screen width (320), and the one that was realoaded with <code>UITableViewRowAnimationAutomatic</code> shifted by <code>Y</code>. </p> <p>The main problem and confusion comes from the fact that I'm unable to change these frames! Well, they change at first, but nothing changes visually and on the other call of <code>viewForHeaderInSection:</code> frames are shifted again.</p> <p>Here is how I do that:</p> <p>Assume we have 3 section, with data of each lays in one of arrays <code>_first</code>, <code>_second</code> and <code>_third</code>. And by button's touchupinside we call <code>handleTouchUp:</code>. (<code>_second</code> remains unchanged)</p> <pre><code>- (void) handleTouchUp: (UIButton *)sender { if ([_first count] == 0) { sectionCount = 3; _first = [NSMutableArray arrayWithObjects: @"First 1", @"First 2", nil]; _third = [NSMutableArray arrayWithObjects: @"Third 1", @"Third 2", @"Third 3", @"Third 4", @"Third 5", nil]; [tableView reloadData]; } else { sectionCount = 2; [_first removeAllObjects]; _third = [NSMutableArray arrayWithObjects: @"First 1", @"First 2", @"Third 1", @"Third 2", @"Third 3", @"Third 4", @"Third 5", nil]; [tableView beginUpdates]; [tableView deleteSections: [NSIndexSet indexSetWithIndex: 0] withRowAnimation:UITableViewRowAnimationRight]; [tableView reloadSections: [NSIndexSet indexSetWithIndex: 2] withRowAnimation:UITableViewRowAnimationAutomatic]; [tableView endUpdates]; } } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSNumber *key = [NSNumber numberWithInteger: section]; UIView *header = [_headers objectForKey: key]; if (header) { } else { header = [[UIView alloc] init]; switch (section) { //Doing something with header here (e.g. set background color) } [_headers setObject:header forKey: key]; } [header setFrame: CGRectMake(0, 0, 320, 25)]; return header; } </code></pre> <p><a href="http://pastie.org/8018139" rel="nofollow">Here is full code of ViewController.m</a> and <a href="http://rghost.net/46572457" rel="nofollow">test project</a> </p> <p><strong>UPDATE:</strong> There may be some other errors in project, but it's not important -- it's test project. The only important problem is invalid header views. Removing invalid view and creating the new one isn't the solution -- it kills the point of reusing header views.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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