我在我的应用程序中使用CAShapeLayer
和UIBezierPath
。我有一个重装按钮。当我多次重新加载视图时,它会给我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
时,我收到此错误。
答案 0 :(得分:0)
由self.layer.sublayers = nil
引起。不加选择地删除所有子图层会导致iOS 7中发生严重的崩溃,这可能会在程序执行后发生。我使用rootLayer.sublayers = nil
和[rootLayer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)]
对此进行了彻底的测试。必须有一个系统创建的图层搞砸了。
您必须保留自己的图层数组并自行删除它们:
[myArrayOfLayersIAdded makeObjectsPerformSelector:@selector(removeFromSuperlayer)];