你好,我正试图在我的UIImagePickerController函数中实现selectFile。(在阿普科达中遵循本教程),但是下面的代码现在是根据我想要的做了一些调整。
@implementation FileBrowser
-(void)selectFile{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
NSString *myURL = [refURL absoluteString]; //not in tutorial, I'm trying to grab the url/path of the image here, with an intention of returning it to "callFileBrowser"
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end根据我所理解的,当用户选择图像时,会调用我的imagePickerController函数。我的问题是,我如何返回(或得到) url?我在同一个文件上有一个C函数(但在@implemetation之外),这个函数调用我的selectFile,并应该返回用户选择的url/路径。
char* callFileBrowser(){
[fileBrowser selectFile];
//return myURL here;
}我希望我能正确地解释一切。如有任何建议,将不胜感激。谢谢。
发布于 2014-10-27 09:22:43
我认为用目前的设计是不可能的。调用callFileBrowser()来选择一个图像,然后立即要求它返回一个值。我们不知道何时会完成用户的选择,我建议您在didFinishPickingMediaWithInfo中发布一个通知,当url准备通知其他需要它的对象时。
https://stackoverflow.com/questions/26584152
复制相似问题