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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 05-30-2008, 05:57 PM   #1 (permalink)
New Member
 
Join Date: May 2008
Posts: 30
Default Removing Last Table Section

Is anybody having luck getting tables to animate properly for editing? I know there were redraw issues with cell addition and deletion in previous betas, but b6 seems to have improved these issues. However, I'm getting bit by something else and I'm not sure if it's my doing or if it's another SDK bug.

I'm going for something similar to the contact editing interface where, in edit mode, new sections appear with a with an "Add new blahblah" cell. It looks like I've got entering edit mode working, but I'm having trouble with exiting edit mode.

Whenever I remove what was previously the final section of the table, I see the following lines in my console:

Fri May 30 17:47:08 esb-pro-2.local app[5807] <Error>: CGImageCreate: invalid image size: 18 x 0.
Fri May 30 17:47:08 esb-pro-2.local app[5807] <Error>: CGImageCreate: invalid image size: 18 x 0.

Eventually, if I toggle in and out of edit mode long enough, the app crashes when it's trying to dealloc a UIImage, so I'm guessing the two are related.

I've tried removing the one-cell editing section both by removing the individual row and removing the whole section - both have the same problem.

I'm curious if anybody has tried something similar or has seen anything like this.
jablair is offline   Reply With Quote
Old 05-30-2008, 07:10 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

I am doing it without any trouble. Are you using insertSections:withRowAnimations:/deleteSections:withRowAnimations:?

The only thing I had trouble with was figuring out what to pass it for the NSIndexSet values because the documentation was very vague in that area. I had all kinds of issues until I realized I was doing that wrong and it works fine now. Feel free to share some code and I can take a look.
jonc is offline   Reply With Quote
Old 05-30-2008, 10:08 PM   #3 (permalink)
New Member
 
Join Date: May 2008
Posts: 30
Default Re: Removing Last Table Section

Yeah, I'm using insertSections:withRowAnimations:/deleteSections:withRowAnimations:

I'm reworking from scratch to see if I can figure out where the problem's coming from. It's tedious, but I'd have to do the same thing separate out the code enough to share. Haven't seen any breakage yet, so maybe I'll get lucky in my restructuring.
jablair is offline   Reply With Quote
Old 05-31-2008, 12:12 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

I am getting strange behavior also, I just didn't realize it earlier. I keep getting the following error when I try to insert rows in a newly created section I add between two other sections (there are a total of 3 including this one, it is going in the middle of the two). If I just add the section (and not the rows)it works fine, but the cells that were already on the screen don't update. When I add the line to insert the rows I get the error. The thing is it starts with one section and you can add the last two in either order, but they always have the same index when added. If I use this same code when I only have one section and add it to the end it works. I can even add the third section after it after that without problems. It seems to be happening after committing all the row changes in my code while the tableView is doing it's thing. Seems like there could be an issue with TableViews, but I never added rows like this before beta 6 so I could be doing something wrong. I have looked over my code for the last 3 hours piecing it apart though, and I am starting to think it could be that tableView has some issues.

Code:
Thread 0 Crashed:
0   libSystem.B.dylib             	0x90585558 tiny_malloc_from_free_list + 62
1   libSystem.B.dylib             	0x9057e3ed szone_malloc + 180
2   libSystem.B.dylib             	0x9057e2f8 malloc_zone_malloc + 81
3   com.apple.CoreFoundation      	0x90777451 _CFRuntimeCreateInstance + 145
4   com.apple.CoreFoundation      	0x907054a8 __CFArrayInit + 184
5   com.apple.CoreFoundation      	0x907e1f25 -[__NSPlaceholderArray initWithCapacity:] + 69
6   com.apple.CoreFoundation      	0x907e2012 -[__NSPlaceholderArray init] + 50
7   UIKit                         	0x30aa656a -[UITableView(_UITableViewPrivate) _updateWithItems:withOldRowData:oldRowRange:newRowRange:] + 2800
8   UIKit                         	0x30aa51a6 -[UITableView(_UITableViewPrivate) _endCellAnimations] + 741
jonc is offline   Reply With Quote
Old 05-31-2008, 01:46 AM   #5 (permalink)
New Member
 
Join Date: May 2008
Posts: 30
Default Re: Removing Last Table Section

Well, it looks like my problems are related to the index when both removing sections and rows (from sections that aren't being removed). Plus, it looks like it's not the last row that's causing problems, but the first one (under certain circumstances).

I basically started over with a sample case that displays any phone numbers, email addresses, and urls for a contact. When you enter edit mode, any sections containing data have an "Add..." button added to the end of the section. Any sections without data (and therefore, not displayed) are added with a single "Add..." row.

If I display a contact with no phone number, but some combination of emails addresses and urls, I get the error I mentioned earlier and the eventual crash. If I display a contact with none of this data, it works fine. If I display a contact with a phone number and some other data, it works fine.

I've been assuming that the insert indexes in this case would be the same as the removal indexes, but this behavior is making me question that assumption. I just have no idea how what the appropriate configuration would be - it took me most of a day to get the the point where I had the proper setup to enter edit mode.

Here's the setEditing function, where I figure out the indixes - I go through each potential section, determine whether it's present, and try to make the appropriate modification to the table.

Code:
- (void)setEditing: (BOOL)editing animated: (BOOL)animated {
	[super setEditing: editing animated: animated];
	
	[self.tableView beginUpdates];
	
	if (editing) {
		NSMutableArray *addedObjects = [[NSMutableArray alloc] init];
		NSUInteger insertLocation = 0;
		
		if ([displayedSections containsObject: [NSNumber numberWithUnsignedInteger: ContactSectionPhone]]) {
			[addedCells addObject: [NSIndexPath indexPathForRow: ABMultiValueGetCount(phoneNumbers) inSection: insertLocation]];
		}
		else {
			[addedSections addIndex: insertLocation];
			[addedObjects addObject: [NSNumber numberWithUnsignedInteger: ContactSectionPhone]];
		}
		insertLocation++;
		
		if ([displayedSections containsObject: [NSNumber numberWithUnsignedInteger: ContactSectionEmail]]) {
			[addedCells addObject: [NSIndexPath indexPathForRow: ABMultiValueGetCount(emailAddresses) inSection: insertLocation]];
		}
		else {
			[addedSections addIndex: insertLocation];
			[addedObjects addObject: [NSNumber numberWithUnsignedInteger: ContactSectionEmail]];
		}
		insertLocation++;
		
		if ([displayedSections containsObject: [NSNumber numberWithUnsignedInteger: ContactSectionURL]]) {
			[addedCells addObject: [NSIndexPath indexPathForRow: ABMultiValueGetCount(urls) inSection: insertLocation]];
		}
		else {
			[addedSections addIndex: insertLocation];
			[addedObjects addObject: [NSNumber numberWithUnsignedInteger: ContactSectionURL]];
		}
		
		[self.tableView insertSections: addedSections withRowAnimation: UITableViewRowAnimationTop];
		[self.tableView insertRowsAtIndexPaths: addedCells withRowAnimation: UITableViewRowAnimationTop];
		[displayedSections insertObjects: addedObjects atIndexes: addedSections];
		[addedObjects release];
	}
	else {
		[self.tableView deleteRowsAtIndexPaths: addedCells withRowAnimation: UITableViewRowAnimationTop];
		[self.tableView deleteSections: addedSections withRowAnimation: UITableViewRowAnimationTop];
		[displayedSections removeObjectsAtIndexes: addedSections];
		[addedCells removeAllObjects];
		[addedSections removeAllIndexes];
	}
	
	[self.tableView endUpdates];
}
jablair is offline   Reply With Quote
Old 05-31-2008, 12:01 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

Quote:
Originally Posted by jablair
If I display a contact with no phone number, but some combination of emails addresses and urls, I get the error I mentioned earlier and the eventual crash. If I display a contact with none of this data, it works fine. If I display a contact with a phone number and some other data, it works fine.
So if there is no phone number you are adding the phone number section above the email/url sections when editing? If so that is the same thing I am doing that is causing problems.
jonc is offline   Reply With Quote
Old 05-31-2008, 01:35 PM   #7 (permalink)
New Member
 
Join Date: May 2008
Posts: 30
Default Re: Removing Last Table Section

Yeah, that about sums up what I'm doing. My problems come when I both add the extra section and add the extra row to the existing section.

Are you making the same assumption about the indixes that I'm making - ie, the insertion and removal indices are the same? I'm leaning towards logging a bug with Apple for this. At least if I'm wrong, maybe they'll point me in the right direction.
jablair is offline   Reply With Quote
Old 05-31-2008, 04:29 PM   #8 (permalink)
New Member
 
Join Date: May 2008
Posts: 30
Default Re: Removing Last Table Section

I'm now really confident this is an Apple bug - if I switch from a grouped table style to a plain table style, I don't get the error messages in the console.
jablair is offline   Reply With Quote
Old 05-31-2008, 05:42 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

I am using a plain style and and having the problem but it sounds like we were doing similar things....

Are you still using section titles/headers in the plain view?
jonc is offline   Reply With Quote
Old 06-01-2008, 02:00 PM   #10 (permalink)
New Member
 
Join Date: May 2008
Posts: 30
Default Re: Removing Last Table Section

Quote:
Originally Posted by jonc
Are you still using section titles/headers in the plain view?
No - I just switched the from specifying UITableViewStyleGrouped to UITableViewStylePlain to get another data point. I didn't bother setting up table sections. My goal is to switch back to the grouped style at a later point.

The plain view isn't perfect though - I've noticed a situation where sometimes a section will get duplicated when I switch into editing mode, regardless of the table style. After toggling in and out of edit mode, I'll eventually see a crash.
jablair is offline   Reply With Quote
Old 06-05-2008, 08:42 PM   #11 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

I am still having tons of trouble with this and can't figure it out. I gave up on doing it in the previous table mentioned in this thread and this is a totally different table with different data and at this point I am almost certain that it is a bug. Has anyone had much luck with removing table sections with headers in the plain style? I have a log style table with rows for certain days that entries are made with section headers dividing it into months. If there are no entries for am month I don't show a header for it. If a row is deleted and it is the last row in the section I also want to delete the section. Every once in awhile the section disappears properly but usually the section header that should have been removed moves down and obscures view of part of the section below. I am even calling reloadData and verifying that my data source is updating, but the graphics are still messed up. If I quit the program and come back in it reloads all the data from the sql db and appears properly with the deleted section header no long obscuring part of the section below.

Am I missing something?

Code:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
	
	if (editingStyle == UITableViewCellEditingStyleDelete) {
		int oldRowCount = [editingDelegate.rootViewController.wDatabase countForMonth:indexPath.section];
		
		
		[self.tableView beginUpdates];
		[editingDelegate.rootViewController.wDatabase deleteW:indexPath.section index:indexPath.row];
			[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
		if(oldRowCount < 2)
			[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];

		[self.tableView endUpdates];
		
		self.lastTouchedIndex = nil;
		[self.tableView setEditing:false animated:false];
		[self.tableView reloadData];

	}
	if (editingStyle == UITableViewCellEditingStyleInsert) {
	}
}
If the old row count is less than 2 there is only one left so the section should also be removed.
jonc is offline   Reply With Quote
Old 06-05-2008, 09:08 PM   #12 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

Also I have found that if I use a if/else like this I won't see any problems but suddenly certain rows stop recieving touches mysteriously like maybe something invisible is over them keeping them from recieving touches.

Code:
if(oldRowCount < 2)
			[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight];		
		else
			[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];

I can also confirm that it is working perfectly without the above code. I commented it out and called reloadData instead, it isn't animated, but the table updates as expected so it doesn't seem to be my data.
jonc is offline   Reply With Quote
Old 06-08-2008, 02:04 PM   #13 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

I can confirm this also happens when removing and inserting at the same index in a grouped table.

I updated my bug report but still haven't heard back. I figure they will have a busy week with WWDC and all.
jonc is offline   Reply With Quote
Old 06-27-2008, 09:32 AM   #14 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 313
Send a message via AIM to jonc
Default Re: Removing Last Table Section

This bug was fixed in Beta 7.

In case anyone else is having trouble with it this is what I did. It isn't documented, but in response to my ticket the engineers told me to remove just the section and not the row when deleting the last row in a section. This works perfectly starting with Beta 7, but not in 6.
jonc is offline   Reply With Quote
Reply

Bookmarks

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default TableView section header background color jonc iPhone SDK Development 4 01-04-2009 12:18 AM
Table view aa233 iPhone SDK Development 1 07-10-2008 06:11 PM
Easily customize table cell. pendraggon87 iPhone SDK Development 4 07-04-2008 08:06 AM
Changing the table frame in a UITableViewController fasttech iPhone SDK Development 1 05-09-2008 09:36 PM
URL schemes in table cells alexanderMobile iPhone SDK Development 3 04-21-2008 01:44 AM


» Advertisements
» Online Users: 267
19 members and 248 guests
2WeeksToGo, @sandris, AdamL, ADY, Dani77, diyora, F_Bryant, GHuebner, HDshot, headkaze, mer10, Oral B, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,748
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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