Advertise here




Advertise here

Howdy, Stranger!

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

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

pigbitepigbite Posts: 2New Users
edited August 2011 in iPhone SDK Development
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
    edited August 2011
    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.