Tôi đang cố gắng theo dõi và phản ứng với giá trị thay đổi của nguồn gốc của khung của UIView. Mã của tôi:iOS: Thêm người quan sát vào frame.origin.y của UIView?
[cell.bottomView addObserver:self forKeyPath:@"frame.origin" options:NSKeyValueObservingOptionNew context:NULL];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"%@ Changed", keyPath);
}
Tôi nhận được thông báo lỗi sau mà tôi không hiểu:
An instance 0x7587d10 of class NSConcreteValue was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x7587fd0> (
<NSKeyValueObservance 0x7587f70: Observer: 0x7587bd0, Key path: origin, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x7587ff0>
)
Thực sự, tôi chỉ quan tâm đến vị trí y về nguồn gốc nhưng mã thậm chí sẽ không biên dịch nếu tôi đặt keyPath thành "frame.origin.y".
Nếu tôi đặt keyPath thành "khung" đơn giản, không có lỗi nhưng phương thức observValueForKeyPath không bao giờ được gọi. Tôi đoán thay đổi về nguồn gốc của khung hình không được tính là thay đổi đối với khung hình ..?
Làm cách nào để hoàn thành việc thêm người quan sát vào frame.origin.y của UIView?
Bạn không gọi siêu trong 'observerValueForKeyPath:'. – Andy