我只是想显示相机或照片库,以便用户可以选择图像并返回应用程序。我终于可以做了,但我面临的问题是,当UIViewController结束时(为什么用户选择图像或用户按下取消的原因取消)应用程序正常工作,但事件停止工作。
我的UIViewController定义如下:
@interface IOSNativeCb : UIViewController
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info;
@end
@implementation IOSNativeCb
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
//log all the dictionary of the selected image
for (id key in info) {
NSLog(@"key: %@, value: %@ \n", key, [info objectForKey:key]);
}
}
//if user canceled
- (void)imagePickerControllerDidCancelUIImagePickerController *)picker {
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[picker dismissViewControllerAnimated:YES completion:^{[self dismissViewControllerAnimated:YES completion:nil];}];
[self removeFromParentViewController];
[window makeKeyAndVisible];
}
@end
我正在用openfl初始化这个:
const void initAppGallery(){
UIWindow *window = [UIApplication sharedApplication].keyWindow;
IOSNativeCb *wn = [[IOSNativeCb alloc] init];
[window addSubview: wn.view];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = wn;
[wn presentModalViewController:picker animated:YES];
[picker release];
}
尝试了几个方法,我如何移除或解除UIViewController以查看该视图是否仍然是主要的,因此事件不再起作用,但到目前为止还没有。
我可以尝试的任何想法?有人有这样的问题吗?是我第一次在objetive-c + haxe编码,所以我有点迷失了什么功能或事情可能是问题。我用一种我几乎不知道的语言盲目编码。
问候。
答案 0 :(得分:0)
可以帮助您找到错误的一些事情:
window.rootViewController = wn
代替[window addSubview:wn.view]
[window makeKeyAndVisible]
。再看看this question,它可能对你有所帮助。
答案 1 :(得分:0)
解决方案更简单,我刚刚在[self removeFromParentViewController];
之后添加:
[self.view removeFromSuperview];
并且工作:D