在NSTableView Objective-c中拖放音频文件

时间:2013-04-02 11:44:19

标签: objective-c macos cocoa nstableview

我想将音频歌曲从桌面拖放到nstableview,我尝试了以下方法,我想知道如何检查文件类型是音频以及如何将这些新文件附加到Library.xml

- (NSDragOperation) tableView: (NSTableView *)tv validateDrop: (id <NSDraggingInfo>)info proposedRow: (NSInteger)row proposedDropOperation: (NSTableViewDropOperation)op
{
[tv setDropRow:[tv numberOfRows] dropOperation:NSTableViewDropAbove];
return NSTableViewDropAbove;
}


- (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation
{
NSPasteboard *myPasteboard=[info draggingPasteboard];
NSArray *typeArray=[NSArray arrayWithObjects:NSFilenamesPboardType,nil];
NSString *filePath,*availableType,*lastPathOfFileName;
NSArray *filesList;
int i;
availableType=[myPasteboard availableTypeFromArray:typeArray];
filesList=[myPasteboard propertyListForType:availableType];
for (i=0;i<[filesList count];i++)
{
    filePath=[filesList objectAtIndex:i];
    lastPathOfFileName=[filePath lastPathComponent];
    NSUInteger No = 1;

    [mySongsArray insertObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%ld",No],@"No",
                                @"testName",@"Name",
                                @"5.0",@"Time",
                                @"Ar.rahman",@"Artist",
                                @"hariharan",@"Album",
                                @"English",@"Genre",nil]  atArrangedObjectIndex:row];
}
testArray = [mySongsArray arrangedObjects];
NSLog(@"testArray===%@",[testArray description]);
return YES;
}

0 个答案:

没有答案