【发布时间】:2014-02-28 20:06:16
【问题描述】:
将动画从 NSTableView 拖放到另一个窗口的 NSTextView 会退回到源视图而不是文本视图。否则,拖放操作可以正常工作——我的数据被粘贴了。我的 NSTextView 的子类在阳光下拥有所有的拖放协议方法(见下面的代码)。可能出了什么问题?
- (void)awakeFromNib { // Adjust default insets
[self setTextViewInset];
[self registerForDraggedTypes:[NSArray arrayWithObjects:AWNDragNDropGeneralRuleRecordType, nil]];
[self registerAsObserver];
}
- (void)registerAsObserver
{
[self addObserver:scrollerSubclass
forKeyPath:@"focused"
options:NSKeyValueObservingOptionNew
context:NULL];
}
- (BOOL)acceptsFirstResponder
{
NSLog(@"Accepting");
[self setFocused:YES];
return YES;
}
- (BOOL)resignFirstResponder
{
NSLog(@"Resigning");
[self setFocused:NO];
[super resignFirstResponder]; // Otherwise cursor remains in textView
return YES;
}
- (BOOL)becomeFirstResponder
{
NSLog(@"Becoming");
return YES;
}
- (void)setFocused:(BOOL)x
{
NSLog(@"-setFocused: is called with %d",x);
focused = x;
}
- (BOOL)focused
{
NSLog(@"-focused: is returning %d",focused);
return focused;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
NSLog(@"prepareForDragOperation YES");
return YES;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSLog(@"draggingEntered:");
if ([sender draggingSource] == self) {
return NSDragOperationNone;
}
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
NSLog(@"Draging Exited:");
[self setNeedsDisplay:YES];
}
- (void)draggingEnded:(id < NSDraggingInfo >)sender
{
[self performDragOperation:sender];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ // Look for drag source in 'SpellRuleFiles.SpellRulesWindowDelegate tableView delegate method
NSPasteboard *pb = [sender draggingPasteboard];
if (![self readFromPasteboard:pb]) {
NSLog(@"Error: Could not read from dragging pasteboard");
NSLog(@"performDragOperation NO");
return NO;
}
NSLog(@"performDragOperation YES");
return YES;
}
- (BOOL)readFromPasteboard:(NSPasteboard *)pb
{ // Source of paste data is 'SpellRuleFile's '
// I'm not showing this code
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
NSLog(@"conclude drag operation:");
[self setNeedsDisplay:YES];
}
【问题讨论】:
标签: cocoa drag-and-drop