mouseDown 方法中的异常

发布于 2024-09-10 13:36:17 字数 1253 浏览 1 评论 0原文

我正在使用 NSView 进行拖放操作。

在要拖动的对象(NSView 的子类)中,我实现了 mouseDown: 方法,如下所示:

@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);
}

大多数时候它工作正常,但问题是 - 有时它会引发此问题

异常:无效参数不 满足: theWriteStream != NULL

,因此拖动的图像会持续出现在屏幕上,即使选择其他窗口也不会消失。

谁能告诉我为什么会发生这种情况以及如何解决它?

谢谢,

米拉杰

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 resolve it?

Thanks,

Miraaj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2024-09-17 13:36:17
异常:无效参数不满足:theWriteStream != NULL

这种异常来自于一个断言。有些东西将尝试写入流,并断言它有一个要写入的流。当断言失败时,意味着条件不成立;在这种情况下,这意味着它没有可写入的流。

我在您提供的示例中没有看到任何与流相关的代码,因此它要么位于您的应用程序中的其他位置,要么位于您正在使用的框架内的某个位置。您应该在 Xcode 中打开“停止 Objective-C 异常”,然后在调试器下运行您的应用程序,直到发生异常,然后查看调试器中的堆栈跟踪以准确了解引发异常的原因。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文