views:

121

answers:

4

If I have a UITableView in edit mode, w/ reordering turned on, it seems I can't move some (but not all) cells into some (but not all) empty sections. For example, if I have this layout :

Section 1
  apple
  banana
Section 2
  doberman
Section 3
Section 4

Then I can move 'doberman' into any slot in section 1 (except after 'banana'), but I can't move it into section 3 or 4 at all.

On the other hand, I can move 'apple' & 'banana' into section section 2 (except after 'doberman'), and I CAN move it into section 3, but NOT into section 4.

What gives? this seems like buggy behavior. How do people work around it? Is apple aware of this bug?

A: 

Hi Jeremy,

Did you find the solution?

Jay
A: 

Yup, it's an apple bug. I talked to apple, used one of my "support tickets" for them to tell me that it's their bad.

I did also hack around it, by moving from the obvious many section table model to a model that only has a single section, and models "section headers" as styled table view cells.

Stupid apple...

Jeremy Lightsmith
+1  A: 

I have used another hack: create a dummy last section with an empty cell (invisible backgroundView) in the edit mode. With this, i can keep the section/row organization, and the reordering works wonderfully, even with the "last" section.

Another way, is to have a section footer with, at least, the same height as your cells. In this case, the cell can go past the last cell of the last section.

Sirdek
A: 

Sirdek is correct. Just copy the following code into your UITableViewDelegate/UITableViewDataSource.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    NSInteger lastSection = [self numberOfSectionsInTableView:tableView] - 1;
    NSInteger lastRow = [self tableView:tableView numberOfRowsInSection:lastSection] - 1;
    CGFloat height = [self tableView:tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:lastSection]];

    return (section == lastSection ? [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, height)] autorelease] : nil);
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    NSInteger lastSection = [self numberOfSectionsInTableView:tableView] - 1;
    NSInteger lastRow = [self tableView:tableView numberOfRowsInSection:lastSection] - 1;
    CGFloat height = [self tableView:tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:lastSection]];

    return (section == lastSection ? height : 0);
}
Lars Schneider