开发者

Missing Cell Contents When Adding "Add New Item" row to bottom row of UITableView

I am creating an "add new item" row to a section in a table view which gets dynamically added/deleted as the editing mode is entered/exited. This works fine however if the table is longer than the screen then the labels for any rows not yet displayed are not shown when you scroll down to see the new "add new item row".

The key parts of my code are:

setEditing...

-(void)setEditing:(BOOL)editing animated:(BOOL)animate
{

    [super setEditing:editing animated:animate];
    [self.tableView setEditing:editing animated:animate];

    NSArray *paths = [NSArray arrayWithObject:
                      [NSIndexPath indexPathForRow:[self.location.rooms count] inSection:kSectionRooms]];
    if (editing)
    {
        [[self tableView] insertRowsAtIndexPaths:paths 
                            withRowAnimation:UITableViewRowAnimationTop];
    }
    else {
        [[self tableView] deleteRowsAtIndexPaths:paths 
                            withRowAnimation:UITableViewRowAnimationTop];
    }

}

numberOfRowsInSection...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

开发者_如何学运维    switch (section) {
        case kSectionFields:
            return NUM_SECTION_FIELDS_ROWS;
            break;
        case kSectionRooms:
            return [location.rooms count] + ([self.tableView isEditing] ? 1 : 0);
            break;
        default:
            return 0;
            break;
    }
return 0;
}

portion of cellForRowAtIndexPath

        if ([self.tableView isEditing] && row == location.rooms.count)
        {

            roomCell.textLabel.text = @"Add new room...";


        }
        else
        {
            roomCell.textLabel.text = [[loc.rooms objectAtIndex:row] name];
        }

editingStyleForRowAtIndexPath....

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {


switch ([indexPath section])
{
    case kSectionFields:
        return UITableViewCellEditingStyleNone;
        break;
    case kSectionRooms:
        if ([indexPath row] == location.rooms.count && [self.tableView isEditing])
        {
            return UITableViewCellEditingStyleInsert;
        }
        else
        {
            return UITableViewCellEditingStyleDelete;
        }

        break;
}

return UITableViewCellEditingStyleNone;

}

These are all working correctly if there is no scrolling but as soon as there is scrolling then I get problems. I understand that this must be due to the fact that the TableView has not displayed the hidden rows and therefore has not gone through the lazy loading process. I've tried using reloadData but that makes no difference (unsurprisingly) but as I am new to this I am not sure of the best way of making the rows appear.

I am sure there will be a simple solution so any ideas would be most appreciated!

Cheers in advance

jez

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜