0

我想将音频歌曲从桌面拖放到 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;
}
4

0 回答 0