我只是想显示相机或照片库,以便用户可以选择图像并返回应用程序。我终于可以做到了,但我面临的问题是,当 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 编码,所以我有点不知道什么功能或东西可能是问题所在。我正在用一种我几乎不知道的语言盲编码。
问候。