Reservation uitableview

I ran into the same problem as desciped in: Crash while trying to move UITableView rows ! All I want to do is perform certain re-entry operations, insert a new cell or delete the selected one.

Sometimes I get:

********* Confirmation error in - [_ UITableViewUpdateSupport _setupAnimationForReorderingRow], / SourceCache / UIKit / UIKit-963.10 / UITableViewSupport.m: 295 Attempt to create two animations to exclude cells

and when I want to reload my data by calling [self.tableView reloadData] I get:

********** Application termination due to an uncaught exception "NSRangeException", reason: "*** - [NSCFArray objectAtIndex:]: index (0) outside bounds (0) '

Is there anyone who knows how to deal with this problem?

0
source share
2 answers

Hallo again!

Thank you for your help! I really found a solution for my problem!

I no longer need tableview animations while editing! I finally found a solution in this post: How to stop the UITableView moveRowAtIndexPath from leaving blank lines when reordering

Tom Saxton said:

// APPLE_BUG: if you move the cell to a line that is off the screen (because the destination // has been changed), the dummy cell is created and will eventually crash

So my code looks like this:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
if( fromIndexPath == toIndexPath ) {
    return;
}

if (toIndexPath.row == [self.data count] -1) { //element has been dragged to the bottom
        self.data removeObjectAtIndex:fromIndexPath.row];
        [self performSelector:@selector(delayedReloadData:) withObject:tableView afterDelay:0];
}
else { //Normal reoder operation
        [self.data removeObjectAtIndex:fromIndexPath.row];
     [self.data insertObject:element atIndex:toIndexPath.row];
}

}

- (void)delayedReloadData:(UITableView *)tableView {
//Assert(tableView == self.tableView);
[self.tableView reloadData];

}

mem initData, :

-(void) initData {
if (!self.data) {
    self.data = [[NSMutableArray alloc] init];
}
else {
    [self.data removeAllObjects];
}

[self.data addObjectsFromArray:[self.fetchedResultsController fetchedObjects]];

}

!

+1

mem initData. , "@property (, ) NSMutableArray *". , alloc/init, 1, self.data, , 2. :

NSMutableArray *ary = [[NSMutableArray alloc] init];
self.data = ary;
[ary release];
0

Source: https://habr.com/ru/post/1732302/


All Articles