Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-07-2011, 01:04 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
pigbite is on a distinguished road
Default 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...

Code:
    -(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...

Code:
    - (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

Code:
			if ([self.tableView isEditing] && row == location.rooms.count)
			{
					
			    roomCell.textLabel.text = @"Add new room...";
					

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

Code:
    - (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
pigbite is offline   Reply With Quote
Old 08-08-2011, 01:35 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
pigbite is on a distinguished road
Default Screenshots

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
Attached Images
File Type: jpg screenshot01.jpg (8.1 KB, 2 views)
File Type: jpg screenshot02.jpg (7.9 KB, 2 views)
File Type: jpg screenshot03.jpg (8.4 KB, 2 views)
File Type: jpg screenshot04.jpg (8.2 KB, 2 views)
pigbite is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, scrolling, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 397
14 members and 383 guests
7twenty7, blasterbr, buggen, chiataytuday, dedeys78, dre, fiftysixty, HemiMG, jimmyon122, jonathandeknudt, LEARN2MAKE, pungs, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0