【问题标题】:Regarding NSoutlineView and WriteItem | Drag-and-Drop Problem关于 NSOutlineView 和 WriteItem |拖放问题
【发布时间】:2011-06-21 07:06:00
【问题描述】:

处理Drag-n-Drop已经做了以下,

-(void)InitMyOutlineView{
 - - - - -  - - - - - - - -  -- - - - - - - -  -
 - - - - - - - - - - - - - -- -- - - - - - - - - 
[pMyOutlineView registerForDraggedTypes:
     [NSArray arrayWithObject:NSStringPboardType]];

/* I tried both Yes and No */   
[pMyOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
- - - -  -- - - - - - -- - - - - - - -- - - - - - 
- -- -- - - - - -- - - - - - - - - - -  - -- - - - 
}

WriteItem 方法如下,

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard{
    [self log:@"write Items"];
    NSString *pStr = [NSString stringWithFormat:@"this is the temp string "];
       [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
       [pboard setString:pStr forType:NSStringPboardType];
       [self log:@"returning YES"];
       return YES;
}

现在我希望控制权会出现在 AcceptDrop 方法中,但是断点没有到达那里,并且在 Log/gdb 中得到以下日志

2011-02-04 16:21:25.435 MyApp[2006:a0f] write Items
2011-02-04 16:21:25.437 MyApp[2006:a0f] returning YES
2011-02-04 16:21:25.439 MyApp[2006:a0f] *** -[NSCFArray initWithObjects:count:]: attempt to insert nil object at objects[0]

并且控制没有来acceptDrop方法,

当我启用“异常停止”时,以下是它停止时的调用堆栈,

#0  0x981b94e6 in objc_exception_throw
#1  0x96ed34cf in -[__NSPlaceholderArray initWithObjects:count:]
#2  0x96efaaa3 in +[NSArray arrayWithObject:]
#3  0x92316dfd in -[NSOutlineView _columnsForDragImage]
#4  0x923f1e32 in -[NSTableView _doImageDragUsingRowsWithIndexes:event:pasteboard:source:slideBack:startRow:]
#5  0x91fea16a in -[NSTableView _performDragFromMouseDown:]
#6  0x91fe89b9 in -[NSTableView mouseDown:]
#7  0x91fe864e in -[NSOutlineView mouseDown:]
#8  0x91f86c68 in -[NSWindow sendEvent:]
#9  0x91e9f817 in -[NSApplication sendEvent:]
#10 0x91e332a7 in -[NSApplication run]
#11 0x91e2b2d9 in NSApplicationMain

让我再更新一件事,在我的大纲视图中,我有自定义单元格,它只是我正在使用的 Mac ImageTextCell 界面文件。

谁能指导我,我做错了什么

亲切的问候 罗汉

【问题讨论】:

    标签: cocoa macos drag-and-drop objective-c++ nsoutlineview


    【解决方案1】:

    [myoutlineView setOutlineColoumn : firstColumn] 丢失, 当我添加时,它的工作很糟糕

    【讨论】:

      【解决方案2】:

      确保您在 Xcode 的 Debug 菜单中打开了“Stop on Objective-C Exceptions”,然后在调试器下运行您的应用程序(启用断点)。抛出异常时调试器将停止,然后您可以调查您尝试使用nil 对象创建数组的位置。

      我发现您显示的代码不太可能是问题的根源,因为您正在传递一个在 AppKit 框架中全局定义的字符串。

      【讨论】:

      • 我正在尝试拖动单行,这是否意味着,在 WriteItem 中我需要存储与该行关联的自定义单元格
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多