2012-03-08 77 views
1

请温柔!我只对我正在做的事情有一个模糊的理解。UIDocumentInteractionController中的“表达结果未使用”

我试图设置UIDocumentInteractionController的Name属性,希望它会在发送到另一个应用程序之前更改文件名。我使用以下来实现:

UIDocumentInteractionController *documentController; 
    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; 
    NSURL *soundFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent: 
                [NSString stringWithFormat: @"%@/%@", kDocumentNotesDirectory, currentNote.soundFile]]]; 

    NSString *suffixName = @""; 
    if (self.mediaGroup.title.length > 10) { 
     suffixName = [self.mediaGroup.title substringToIndex:10]; 
    } 
    else { 
     suffixName = self.mediaGroup.title; 
    } 
    NSString *soundFileName = [NSString stringWithFormat:@"%@-%@", suffixName, currentNote.soundFile]; 

    documentController = [UIDocumentInteractionController interactionControllerWithURL:(soundFileURL)]; 
    documentController.delegate = self; 
    [documentController retain]; 
    documentController.UTI = @"com.microsoft.waveform-​audio"; 
    documentController.name = @"%@", soundFileName; //Expression Result Unused error here 
    [documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 

我在这条线得到一个“表达式结果未使用”错误:

documentController.name = @"%@", soundFileName; 

我失去了我的脑海里想了明白这一个。任何援助表示赞赏。

+1

删除@“%@”, – 2012-03-08 19:42:44

回答

1

可惜你不能这样创建一个字符串:

documentController.name = @"%@", soundFileName; 

@"%@"是文字NSString,但是编译器不会为你做任何格式/更换。你必须明确地拨打电话到的字符串构造方法之一:

documentController.name = [NSString stringWithFormat:@"%@", soundFileName]; 

在这种情况下,虽然,因为soundFileName本身就是一个NSString,所有你需要做的就是分配:

documentController.name = soundFileName; 

的你得到的警告是编译器告诉你,逗号后面的位(你指的是soundFileName)正在被评估并被丢弃,这真的是你的意思吗?

在C中,因此在ObjC中,逗号是一个可以分隔语句的运算符;每个都分开评估。因此,您得到警告的这条线路可能会被重写:

documentController.name = @"%@"; 
soundFileName; 

正如您所看到的,第二行完全不起作用。

+0

感谢您提供丰富的答案!不幸的是,被发送到其他应用程序的文件的名称没有被更改,但是。除非有明显的事情让你感到震惊,否则我会在做一些四处搜寻之后另存一个问题。 – user1257826 2012-03-08 22:25:27

+0

检查'soundFileName'和其他使用'NSLog'创建的变量:'NSLog(@“%@,%@,%@”,suffixName,currentNote.soundFile,soundFileName);'确保它们是你期望他们是什么。 – 2012-03-09 06:56:40

+0

我试图做同样的 - 名称不会改变。我可以改变UTI而不是名字;( – slott 2012-09-04 07:09:25

相关问题