I have UILabels that are dragged and dropped by the user from one UIView to another. More specifically:
-Upon being touched, each such label moves from its parent view to the main view of the view controller, but in didMoveToSuperview a reference is created to the original UIView if the variable is nil.
-Upon being released, the view controller then decides what to do. If the view controller decides that the label is close enough to where it should now be, it copies the text into a "destination" UIView and then tells the label to go back to where it was originally. Otherwise, the label just goes back to where it was originally.
Because of a problem my client was having - wherein the UILabel seemed to have been put back I put an NSLog statement in my UILabel subclass's didMoveToSuperview method. That NSLog now seems to be logging (null) for the superview.
Here's the code:
-Upon being touched, each such label moves from its parent view to the main view of the view controller, but in didMoveToSuperview a reference is created to the original UIView if the variable is nil.
-Upon being released, the view controller then decides what to do. If the view controller decides that the label is close enough to where it should now be, it copies the text into a "destination" UIView and then tells the label to go back to where it was originally. Otherwise, the label just goes back to where it was originally.
Because of a problem my client was having - wherein the UILabel seemed to have been put back I put an NSLog statement in my UILabel subclass's didMoveToSuperview method. That NSLog now seems to be logging (null) for the superview.
Here's the code:
Code:
-(void)didMoveToSuperview
{
NSLog(@"Label with text %@ moved to superview %@",[selftext],[selfsuperview]);
if (originalSuperview == nil) {
// Label is going to be dragged to another location.
[selfsetUserInteractionEnabled:true];
originalSuperview = [selfsuperview];
}
}