Exception in mouseDown method
I am doing drag and drop with NSView.
In the object to be dragged, which is subclass of NSView, I implemented mouseDown: method as follows:
@try {
NSPoint location;
NSSize size ;
NSPasteboard *pb = [NSPasteboard pasteboardWithName:@"CameraIconContainer"];
location.x = ([self bounds].size.width - size.width)/2 - 21.0;
location.y = ([self bounds].size.height - size.height)/2 - 7.0;
NSLog(@"mouseDown: location- (%f, %f)",location.x,location.y);
NSDictionary *iconViewDict = [[NSDictionary alloc] initWithObjectsAndKeys:[cameraNo stringValue],@"cameraNo",nil];
NSLog(@"iconViewDict - %@",iconViewDict);
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:iconViewDict];
[pb declareTypes:[NSArray arrayWithObject:IconDragDataType] owner:self];
[pb setData:data forType:IconDragDataType];
[self dragImage:[NSImage imageNamed:@"camera_icon.png"] at:location offset:NSZeroSize event:e pasteboard:pb source:self slideBack:YES];
}
@catch (NSException * e) {
NSLog(@"CameraIconView (-mouseDown:), error - %@",e);
}
Most of the time it is working fine but problem is- sometimes it is raising this
exception:Invalid parameter not satisfying: theWriteStream != NULL
in the mouseDown: method, because of it the dragged image continuously appears over screen, which does not disappear even if some other window is selected.
Can anyone suggest me why is it occurring and how can I开发者_如何学JAVA resolve it?
Thanks,
Miraaj
exception:Invalid parameter not satisfying: theWriteStream != NULL
That sort of exception comes from an assertion. Something is about to try to write to a stream, and asserted that it has a stream to write to. When the assertion fails, that means that the condition was untrue; in this case, it means that it did not have a stream to write to.
I don't see any stream-related code in the sample you provided, so it's either somewhere else in your app or somewhere within a framework you're using. You should turn on “Stop on Objective-C exceptions” in Xcode, then run your app under the debugger until the exception occurs, then look at the stack trace in the debugger to see exactly what threw the exception.
精彩评论