2014-01-07 82 views
0

我只是試圖顯示相機或照片庫,以便用戶可以選擇圖像並返回到應用程序。我終於可以做到了,但我面臨的問題是,當UIViewController結束時(爲什麼用戶選擇了圖像或爲什麼用戶按下取消),該應用程序可以工作,但事件停止工作。主應用程序停止響應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

有些事情,可以幫助您找到錯誤:

  1. 使用window.rootViewController = wn而不是[window addSubview:wn.view]
  2. 打完電話後不要鬆開拾取[選擇器dismissModalViewControllerAnimated:YES。您已經發布了選擇器一旦上了initAppGallery方法,所以再次釋放它可能導致未知的問題(可能崩潰)
  3. 調用[window makeKeyAndVisible]應在initAppGallery年底完成。

再看看this question,它可能會幫助你一點。

+0

1)'window.rootViewController = wn'取代我的應用主屏幕與視圖控制器,所以,當我回來時,視圖不再存在:( –

0

被更簡單,我只是[self removeFromParentViewController];後加入溶液:

[self.view removeFromSuperview]; 

和工作:使用d