Question

using completion with animateWithDuration causes exc_bad_access

I am trying to animate 2 UIButtons in a UITableViewCell called addToPlaylist and removeFromPlayList (they animate off to the right after being swiped on) and am using a block as follows

[UIView animateWithDuration:0.25 animations:^{

    self.addToPlaylist.center      = CGPointMake(contentsSize.width + (buttonSize.width / 2), (buttonSize.height / 2));
    self.removeFromPlaylist.center = CGPointMake(contentsSize.width + (buttonSize.width / 2), (buttonSize.height / 2));
    myImage.alpha = 1.0;

}
 completion:^ (BOOL finished) 
 {
     if (finished) {
         // Revert image view to original.
         NSLog(@"Is completed");
         self.addToPlaylist.hidden       = YES;
         self.removeFromPlaylist.hidden  = YES;
         self.hasSwipeOpen               = NO;
     }
 }];

on completion I want to hide the buttons to attempt to lessen redraw on scroll etc.

This code sits within '-(void) swipeOff' which is called in the UITableViewControllers method scrollViewWillBeginDragging like so:

- (void)scrollViewWillBeginDragging:(UIScrollView *) scrollView
{
   for (MediaCellView* cell in [self.tableView visibleCells]) {
        if (cell.hasSwipeOpen) {
           [cell swipeOff];
        }
    }
}

The problem is the completion code, if I remove it or set it to nil all is good, if I include it I get an EXC_BAD_ACCESS. even if I include it with any or all of the lines within the if(finished) commented out

Am I using this in the wrong way, any help much appreciated.

Thanks

 21  13403  21
1 Jan 1970

Solution

 20

I had the same problem with animations. I've solved it by removing -weak_library /usr/lib/libSystem.B.dylib from Other Linker flags.

Also, according to this answer, if you need this flag, you may replace it with -weak-lSystem.

2011-06-10

Solution

 0

Check if you are not calling a UIView (collectionView, Mapview, etc) from inside the UIView block, meaning, it would be a call outside the main thread. If you are, try this:

DispatchQueue.main.async {
self.mapBoxView.setZoomLevel(self.FLYOVERZOOMLEVEL, animated: true
)}
2019-04-11