获取错误的访问错误

时间:2013-08-28 12:07:07

标签: ios exc-bad-access

我在我的应用程序中使用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时,我收到此错误。

1 个答案:

答案 0 :(得分:0)

self.layer.sublayers = nil引起。不加选择地删除所有子图层会导致iOS 7中发生严重的崩溃,这可能会在程序执行后发生。我使用rootLayer.sublayers = nil[rootLayer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)]对此进行了彻底的测试。必须有一个系统创建的图层搞砸了。

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

[myArrayOfLayersIAdded makeObjectsPerformSelector:@selector(removeFromSuperlayer)];