Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

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
Post edited by pigbite on

Replies

  • pigbitepigbite Posts: 2New Users
    Here are some screen shots to show exactly what is happening...

    The screenshots show the original screen, the scrolled screen outside of edit mode, the screen in edit mode before scrolling and the scrolled edit mode screen.

    Any ideas would be gratefully received!

    Rgds


    Jez
    screenshot01.jpg
    1 x 1 - 8K
    screenshot02.jpg
    1 x 1 - 8K
    screenshot03.jpg
    1 x 1 - 8K
    screenshot04.jpg
    1 x 1 - 8K
Sign In or Register to comment.