我已经和这个问题斗争了一段时间了。我正在开发文件复制管理器模块,到目前为止,除了取消按钮之外,我已经能够使一切正常工作。由于某种原因,当我单击特定行的取消按钮时,按钮操作同时针对多行。

经过几天的研究这个问题后,我能够使用以下命令使对象成功取消该行所代表的操作:
-(IBAction)btnCancelOperationClick:(id)sender {
NSInteger row = [_tableView rowForView:sender];
if (row != -1) {
FileCopyOperation *opr = [_fileCopyOperations objectAtIndex:row];
[opr cancel];
[_fileCopyOperations removeObjectAtIndex:row];
[_tableView removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] withAnimation:NSTableViewAnimationEffectFade];
}
}
Run Code Online (Sandbox Code Playgroud)
这很好用,我可以取消操作并相应地更新我的表。其他一切都按预期工作,但我的代码或绑定一定有问题。我从笔尖加载此单元格,然后使用以下方法注册此笔尖:
[_tableView registerNib:[[NSNib alloc]initWithNibNamed:@"FileCopyCell" bundle:nil] forIdentifier:@"FileCopyCell"];
Run Code Online (Sandbox Code Playgroud)
我将 QueueController 设置为文件的所有者,并像这样挂钩所有内容:

如果有人能为我指出正确的方向以使这件事正常工作,我将不胜感激。提前致谢!
编辑以添加更多代码示例。
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
FileCopyCell *cell = [tableView makeViewWithIdentifier:@"FileCopyCell" owner:self];
FileCopyOperation *opr = [_fileCopyOperations objectAtIndex:row];
[cell.fileName setStringValue:[NSString stringWithFormat:@"Copying \"%@\"",opr.fName]];
[cell.progressBar setDoubleValue:((opr.bWritten.doubleValue / opr.fSize.doubleValue) * 100)];
[cell.totalBytes setStringValue:[NSString stringWithFormat:@"of %@",[NSByteCountFormatter stringFromByteCount:opr.fSize.longLongValue countStyle:NSByteCountFormatterCountStyleFile]]];
[cell.status setStringValue:[NSString stringWithFormat:@"%@",[NSByteCountFormatter stringFromByteCount:opr.bWritten.longLongValue countStyle:NSByteCountFormatterCountStyleFile]]];
[cell.icon …Run Code Online (Sandbox Code Playgroud) 我已经用头撞墙大约两周了,我查看了所有可用的 Apple 文档以及数百个网站,寻找解决我的问题的提示。我正在实施:
-(void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexes
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是拖动文件的图标显示在不同的坐标系中,并且我似乎无法找到一种方法使图标显示在拖动开始的屏幕点上。我已经研究了几种组合中的所有 [tableView Convert* ] 方法,但没有成功。下面是我当前正在使用的代码。
-(void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexes {
[session enumerateDraggingItemsWithOptions:NSDraggingItemEnumerationConcurrent
forView:tableView
classes:[NSArray arrayWithObjects:[NSPasteboardItem class], nil]
searchOptions:nil
usingBlock:^(NSDraggingItem *draggingItem, NSInteger index, BOOL *stop)
{
NSMutableArray *videos = [NSMutableArray array];
for (Video* video in [_arrayController selectedObjects]) {
[videos addObject:video.url];
}
NSImage *draggedImage = [[NSWorkspace sharedWorkspace]iconForFiles:videos];
NSPoint mouseLocInView = [tableView convertPoint:[tableView.window convertRectFromScreen:NSMakeRect(screenPoint.x,screenPoint.y, 0, 0)].origin fromView:nil];
NSLog(@"Mouse location in view: X: %f, Y: %f",mouseLocInView.x, mouseLocInView.y);
NSLog(@"Screen point: X: %f, …Run Code Online (Sandbox Code Playgroud) 什么更有效率?为什么?
选项1:
int n = someFunction();
for (int i = 0; i < n ; i++)
//do something...
Run Code Online (Sandbox Code Playgroud)
选项2:
for (int i = 0; i < (someFunction()); i++)
//do something...
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的回复!