On May 13, 2013, at 11:38 PM, Quincey Morris
<[email protected]> wrote:
> On May 13, 2013, at 19:41 , Graham Cox <[email protected]> wrote:
>
>> When you call -removeFromSuperview, the view is deleted, as there are no
>> more references to it. The other methods are not called because the object
>> ceases to exist.
>
> I believe your warning is apposite, but is not actually the cause of Tom's
> problem. After removing the view, his code adds it back again. If the view
> had already been deallocated, you'd expect a pretty big crash pretty soon
> (though not necessarily immediately).
>
> My guess is that the removed view is still retained by something,
I believe ARC keeps it alive by virtue of self being a strong reference. I did
a quick test and found that if I do
- (void) mouseDown: (NSEvent*) event
{
NSView* superView = [self superview];
[self removeFromSuperview];
// [superView addSubview: self];
}
...then dealloc does in fact get called. But if I uncomment that one line,
which references self, dealloc does not get called. This is good news -- I
would want ARC to work regardless of whether it calls non-ARC code, and vice
versa.
> but that removing a view from its window causes the mouse-dragging state
> machine to be reset. If so, immediately re-adding the view isn't going to
> restore the dragging state.
This sounds very plausible.
>
> I think the trick is to avoid removing the view from its superview. I'm not
> sure of the *best* way of doing this, but here are the things I'd try:
>
> -- Invoke 'addSubview: self' without first removing self.
On May 13, 2013, at 11:56 PM, Thomas Wetmore <[email protected]> wrote:
> This works. Thanks for the tip.
Oh, good. I was going to suggest instead of removing and re-adding self, that
you remove and re-add all the sibling views that are in front of self so that
they are behind self, using addSubview:positioned:relativeTo:. That would have
been very ugly.
--Andy
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]