1

我在我的应用程序中使用CAShapeLayerUIBezierPath。我有一个重新加载按钮。当我多次重新加载视图时,它给了我一个EXC_BAD_ACCESS错误。这是我的代码:

self.layer.sublayers = nil;
NSInteger numOfDays = [self differenceBetweenTwoDatesFromDate:startDate toDate:endDate];
CGFloat widthOfComponent = numOfDays * dayWidth;
if (self.frame.size.width > widthOfComponent) {
    DLog(@"%@",NSStringFromCGRect(self.frame))
    widthOfComponent = self.frame.size.width - 2 * DIFFERENCE_FROM_ORIGIN;
    dayWidth = widthOfComponent/numOfDays;
}
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, widthOfComponent, self.frame.size.height);

[self reloadData];

[super layoutSubviews];

当我将新框架传递给self.frame.

4

1 回答 1

0

是由self.layer.sublayers = nil. 不加选择地删除所有子层会在 iOS 7 中导致严重的崩溃,这可能会在程序执行的更晚发生。我已经使用rootLayer.sublayers = nil和彻底测试了这一点[rootLayer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)]。一定有一个系统创建的层被搞砸了。

您必须保留自己的图层数组并自己删除它们:

[myArrayOfLayersIAdded makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
于 2014-01-28T08:14:25.080 回答