How to stop UITableView moveRowAtIndexPath from leaving blank rows upon reordering?

SO... Actually problem is in Three20 framework. TTTableView, which is subclass of UITableView have two buggy methods.

Up vote 3 down vote favorite 1 share g+ share fb share tw.

I am having an issue where in reordering my UITableViewCells, the tableView is not scrolling with the cell. Only a blank row appears and any subsequent scrolling gets an Array out of bounds error without any of my code in the Stack Trace. Here is a quick video of the problem.

Here is the relevant code: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return indexPath. Section == 1; } - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { BOOL ret = indexPath. Section == 1 && indexPath.

Row = count) { return NSIndexPath indexPathForRow:count-1 inSection:sourceIndexPath. Section; } return proposedDestinationIndexPath; } …thats about it. I am using the three20 framework and I have not had any issues with reordering till now.

The problem is also not in the updateCellBackgroundPositionsForTableView: method as it still crashes when this is commented out. Iphone cocoa-touch uitableview crash reorder link|improve this question edited Feb 13 '10 at 0:41 asked Feb 11 '10 at 5:02coneybeare14.4k53774 100% accept rate.

Provide call stack when crash is occured. Are you sure, that it's no connected with your updateCellBackgroundPositionsForTableView method? – tt.

Kilew Feb 13 '10 at 0:10 The stack trace does not contain any of my code (not to say I am not causing it) but there is no useful information in there in regards to lines of code. I will update the stacktrace above anyway – coneybeare Feb 13 '10 at 0:24 Can you add the code for updateCellBackgroundPositionsForTableView? And other UITableViewDataSource-related methods?

I have another suggestion. I think you have problem with creating/reusing cells... Need more code... more code... :) – tt. Kilew Feb 13 '10 at 0:28 I don't have much more code for you to see… I am using the excellent three20 framework.

Also, the crash is definitely not in the updateCellBackgroundPositionsForTableView method as it still crashes when this is commented out. – coneybeare Feb 13 '10 at 0:42 I've added all your methods in my project and all works fine. Problem is in another methods of this dataSource.

Or Maybe in TableViewDelegate. – tt. Kilew Feb 13 '10 at 0:51.

SO... Actually problem is in Three20 framework. TTTableView, which is subclass of UITableView have two buggy methods: /////////////////////////////////////////////////////////////////////////////////////////////////// // UIScrollView - (void)setContentSize:(CGSize)size { if (_contentOrigin) { CGFloat minHeight = self. Height + _contentOrigin; if (size.

Height Y; super setContentSize:size; if (_contentOrigin) { // As described below in setContentOffset, UITableView insists on messing with the // content offset sometimes when you change the content size or the height of the table self. ContentOffset = CGPointMake(0, y); } } - (void)setContentOffset:(CGPoint)point { // UITableView (and UIScrollView) are really stupid about resetting the content offset // when the table view itself is resized. There are times when I scroll to a point and then // disable scrolling, and I don't want the table view scrolling somewhere else just because // it was resized.

If (self. ScrollEnabled) { if (!(_contentOrigin && self.contentOffset. Y == _contentOrigin && point.

Y == 0)) { super setContentOffset:point; } } } Just comment them, And all will works fine. I don't know if this will destroy something somewhere, but at least, you know where the problem is.

Thanks! I have actually isolated it even further with your guidance. The problem is that when reordering the row, self.

ScrollEnabled is NO so the super line is not called. I am going to have to look into why this was done (I'm sure it had a reason) but it might be so obscure that I can change it back. – coneybeare Feb 13 '10 at 4:25.

Cross-posting my answer to this related question: I just hit what I believe is the same problem in my app. The situation is that I have two table sections. Items can be dragged within and between sections.

Users can drag cells to any row in the first section, but in the second section the items are sorted, so for any given cell, there's only one valid row. If I scroll the view so that the bottom of section 1 and the top of section 2 are visible, grab an item in section 1 that sorts to the bottom of section 2, and drag it into the the top of section 2, my tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: method gets called and I return the correct destination position, which is several rows below the bottom of the screen. In the UI, you can see an empty cell gets created at the bottom of the screen, which is not the correct destination row.

When you let go of the cell, that bogus cell that was created at the bottom of the screen (in the middle of section 2) stays there! TableView:cellForRowAtIndexPath: never even gets called for it. As soon as you try to do anything with that cell, you crash.

My first solution was to just call tableView reloadData at the end of tableView:moveRowAtIndexPath:toIndexPath:. But that causes a crash, so instead I call it indirectly after a delay. But then there's another bug: after the delayed reloadData call, tableView:moveRowAtIndexPath:toIndexPath: gets called again with a bogus request to move an item one past the end of the first section to that same position.

So, I had to add code to ignore bogus no-op requests. So, here's the code: - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)pathSrc toIndexPath:(NSIndexPath *)pathDst { // APPLE_BUG: after doing the delayed table reload (see below), we get a bogus // request to move a nonexistant cell to its current location if (pathSrc. Row == pathDst.

Row && pathSrc. Section == pathDst. Section) return; // update your data model to reflect the move... // APPLE_BUG: if you move a cell to a row that's off-screen (because the destination // has been modified), the bogus cell gets created and eventually will cause a crash self performSelector:@selector(delayedReloadData:) withObject:tableView afterDelay:0; } - (void)delayedReloadData:(UITableView *)tableView { Assert(tableView == self.

TableView); tableView reloadData; } Note that there's still a UI bug. On the screen, the dragged cell gets animated into the bogus empty cell. At the end of the animation, the empty cell gets redrawn with the correct data for that row, but the observant user will notice the dragged cell getting animated to the wrong spot then instantly morphed to a different cell.

This is definitely a goofy UI. I considered scrolling the proper destination row onto the screen, but if I were to do that it would fill the screen with section two and then any attempt to drag back to section one would be continually thwarted by my (now annoying) autoscrolling. I may have to change the UI, but that would require some complex and bothersome changes to my data model.

Hallo Tom! You actually solved my problem! For detailed information see: stackoverflow.com/questions/3014906/rera... Thank you very much!

– Nicolay Jun 11 '10 at 7:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions