【问题标题】:using completion with animateWithDuration causes exc_bad_access将完成与 animateWithDuration 一起使用会导致 exc_bad_access
【发布时间】:2011-05-11 00:06:18
【问题描述】:

我正在尝试为名为 addToPlaylist 和 removeFromPlayList 的 UITableViewCell 中的 2 个 UIButton 设置动画(它们在被滑动后向右移动)并且正在使用如下块

[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;
     }
 }];

完成后我想隐藏按钮以尝试减少滚动等重绘。

此代码位于 UITableViewControllers 方法 scrollViewWillBeginDragging 中调用的 '-(void) swipeOff' 中,如下所示:

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

问题是完成代码,如果我删除它或将它设置为 nil 一切都很好,如果我包含它,我会得到一个 EXC_BAD_ACCESS。即使我将它包含在 if(finished) 中的任何或所有行中都已注释掉

我是否以错误的方式使用它,非常感谢任何帮助。

谢谢

【问题讨论】:

  • 如果你省略分配并保留 NSLog,代码是否可以正常工作而不会崩溃?它总是崩溃还是仅仅在 tableview 滚动时崩溃?
  • 嗨尼克,它仍然会崩溃,只有 NSLog 在那里,只有当 tableView 滚动时

标签: iphone objective-c-blocks


【解决方案1】:

我对动画也有同样的问题。我已经通过从其他链接器标志中删除 -weak_library /usr/lib/libSystem.B.dylib 来解决它。

另外,根据this answer,如果你需要这个标志,你可以用-weak-lSystem替换它。

【讨论】:

  • 谢谢伙计,我已经放弃了那个。我不得不使用 -weak-lSystem 但它摆脱了崩溃/错误。 +1 链接
【解决方案2】:

检查您是否没有从 UIView 块内部调用 UIView(collectionView、Mapview 等),也就是说,这将是主线程外部的调用。如果你是,试试这个:

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

【讨论】:

    猜你喜欢
    • 2019-09-19
    • 2014-01-28
    • 2019-12-31
    • 2019-08-04
    • 2011-06-30
    • 1970-01-01
    • 2013-11-11
    • 2014-12-25
    • 2016-04-08
    相关资源
    最近更新 更多