崩溃在actionForLayer:forKey:

Ein*_*din 12 iphone exc-bad-access calayer uiview ios

在更改一些UILabel的帧时,我有一个神秘的EXC_BAD_ACCESS.崩溃是随机的,通常我必须重复几分钟的条件.

启用NSZombies以及其他内存调试标志(NSDebugEnabled,MallocStackLogging)没有帮助,崩溃仍然保持不透明:只是一个BAD_ACCESS,控制台中没有消息.目标似乎是正确和活跃的,所以它看起来不像是一个解除分配的内存问题.

为了获得更多信息,我将UILabel子类化并重写了崩溃函数:

@implementation TestUILabel
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event {
    return [super actionForLayer:layer forKey:event];
}
@end
Run Code Online (Sandbox Code Playgroud)

它在super的方法中崩溃,但在检查时一切似乎都是正确的(打印retainCount为'self'和'layer'分别给出3和2):

(gdb)po self

<TestUILabel:0x6ac2800; baseClass = UILabel; frame =(173 174; 0 0); text ='54m²'; opaque = NO; autoresize = LM + TM; autoresizesSubviews = NO; userInteractionEnabled = NO; 动画= {position = <CABasicAnimation:0xe07ba60>; }; layer = <CALayer:0xbf1b950 >>

(gdb)po事件

界限

(gdb)po层

<CALayer:0xbf1b950; position = CGPoint(173 174); bounds = CGRect(0 0; 0 0); delegate = <TestUILabel:0x6ac2800; baseClass = UILabel; frame =(173 174; 0 0); text ='54m²'; opaque = NO; autoresize = LM + TM; autoresizesSubviews = NO; userInteractionEnabled = NO; 动画= {position = <CABasicAnimation:0xe07ba60>; }; layer = <CALayer:0xbf1b950 >>; contents = <CGImage 0xe04ed60>; 不透明度= 1; 动画= [position = <CABasicAnimation:0xe07ba60>]>

有人得到类似的问题吗?或者有什么想法可以来自哪里?

提前致谢 !

编辑:这是完整的崩溃回溯:

线程1,队列:
com.apple.main-thread
#0 0x00459b2c in - [UIView(CALayerDelegate)actionForLayer:forKey:]()
#1 0x00eaaac7 in - [CALayer actionForKey:]()
#2 0x00ea80fe in actionForKey(CALayer*, CA :: Transaction*,NSString*)()
#3 0x00ea8066在beginChange(CALayer*,CA :: Transaction*,unsigned int,objc_object*&)()
#4 0x00eaba3a in CALayerSetPosition(CALayer*,CA :: Vec2 const&, bool)()
#5 0x00eab8b5 in - [CALayer setPosition:]()
#6 0x00eab7cc in - [CALayer setFrame:]()
#7 0x0045739d in - [UIView(Geometry)setFrame:]()
#8 0x00542a68 in - [UILabel setFrame:]()
#9 0x0000a97f in - [MosaicElementView setupWithAdvert:] at /Users/eino/Prog/AJ/Classes/Search/SubViews/MosaicElementView.m:30#10
0x00079cb9 in - [SearchResultsViewController setupElement:withCell:indexPath:actualIndex :]()
#11 0x000797a2 in - [SearchResultsViewController tableView:cellForRowAtIndexPath:]()
#12 0x004957fa in - [UITableView(UITableViewInternal)_createPreparedCellForGlobalRow:withIndexPath:]()
#13 0x0048b77f in - [UITab leView(UITableViewInternal)_createPreparedCellForGlobalRow:]()
#14 0x004a0450 in - [UITableView(_UITableViewPrivate)_updateVisibleCellsNow:]()
#15 0x00498538 in - [UITableView layoutSubviews]()
#16 0x00eb0451 in - [CALayer layoutSublayers]()
#17 0x00eb017c in CALayerLayoutIfNeeded()
#18 0x00ea937c在CA :: Context :: commit_transaction(CA :: Transaction*)()
#19 0x00ea90d0 in CA :: Transaction :: commit()()
#20 0x00ed97d5 in CA :: Transaction :: observer_callback( __CFRunLoopObserver*,无符号长,无效*)()
#21 0x017e9fbb在__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__()
在__CFRunLoopDoObservers#22 0x0177f0e7()
在__CFRunLoopRun#23 0x01747bd7()
在CFRunLoopRunSpecific#24 0x01747240()
在CFRunLoopRunInMode#25 0x01747161()
#26 0x01e7d268在GSEventRunModal()
#27 0x01e7d32d in GSEventRun()
#28 0x0043042e in UIApplicationMain()
#29 0x000021fe in main at /Users/eino/Prog/AJ/main.m:11

第9帧的删除线基本上只是帧的变化:

labelPrice.frame = rect;
Run Code Online (Sandbox Code Playgroud)

rect是正确的CGRect(106,143,86,22).

Dav*_*dge 10

你可能已经检查了这个,但它值得一试......

你确定你没有做任何会影响后台线程中任何UI元素的事情吗?也许您正在进行与此搜索相关的一些计算,并且它会更改某个视图的属性.

在我忘记了performSelectorOnMainThread:withObject:waitUntilDone:调用然后在后台更改UI的情况下,我已经看到了他的那种事情.