Problem: a declared property in a NSView subclass doesn't update members bound 
to it (with bindings) when in a mouseDragged method.

So I have a subclass of NSView that has an ivar that I declare as a property.  
In IB I have a NSTextField that I set the binding to the same variable (and I 
do everything required to add the NSView, use an IBOutlet in the AppDelegate, 
etc).  I can confirm that the binding is connected because I set the ivar in 
the initWithFrame method and the NSTextField shows that value.  Also I tried 
adding a button and connected it to an IBAction method, which worked fine.

But when I click and drag the mouse and attempt to update the ivar with 
self.ivar within the mouseDragged (which I confirmed that it's being called), 
it doesn't update the ivar.  I tried also updating it in the mouseUp method and 
that didn't work either. 

The only thing I can think of is it has something to do with the thread that 
bindings are in, which must be different that the thread that mouseDragged is 
in, but I can't confirm that nor know how to deal with it.  Below is my code 
for my mouseDragged method.  Any help would be greatly appreciated.



-(void) mouseDragged:(NSEvent *)theEvent {
    NSPoint mouseLocation = [theEvent locationInWindow];
    NSPoint convertedLocation = [self convertPoint:mouseLocation fromView:nil];
    CGFloat difference = convertedLocation.y - dragStart;
    
    if([theEvent modifierFlags] & NSCommandKeyMask) // command key
        myDial->rotation = dragDialPos - (difference * 0.5);
    else
        myDial->rotation = dragDialPos - (difference * 3);
    
    // check limits
    if(myDial->rotation>= dialMaxLeft)
        myDial->rotation= dialMaxLeft;
    if(myDial->rotation<= dialMaxRight)
        myDial->rotation= dialMaxRight;
    
    
    // set the dialVal
    // this assumes that the range is 300 from -150 to 150
    self.dialValue = (float) (-(myDial->rotation + 150.0) / 300.0) + 1.0;
        
    [selfsetNeedsDisplay:YES];
}


GW
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to