2010-04-01 13 views
0

下面的代碼。UIImagePickerController在使用相機後沒有做任何事情,當我點擊「使用」按鈕

當我在拍照後點擊「使用」按鈕...應用程序變得完全沒有響應。任何想法我做錯了什麼?當在UIViewController視圖上按下按鈕時,將調用「addPlayer:」方法。

感謝

- (IBAction) addPlayers: (id)sender{ 
    // Show ImagePicker 
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
    imagePicker.delegate = self; 

    // If camera is available use it and display custom overlay view so that user can add as many pics 
    // as they want without having to go back to parent view 
    if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { 
     imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 

    } 
    else { 
     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 

    [self presentModalViewController:imagePicker animated:YES]; 
    [imagePicker release]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    // Grab original image 
    UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage]; 

    // Resize photo first to reduce memory consumption 
    [self.photos addObject:[photo scaleToSize:CGSizeMake(200.0f, 300.0f)]]; 

    // Enable *PLAY* button if photos > 1 
    if([self.photos count] > 1) btnStartGame.enabled = YES; 

    // Update player count label 
    lblPlayerCount.text = [NSString stringWithFormat:@"%d", [self.photos count]]; 

    // Dismiss picker if not using camera 
    picker dismissModalViewControllerAnimated:YES]; 

} 
+0

它停止在該行的日期? – willcodejavaforfood 2010-04-01 08:41:47

+0

您的「使用」按鈕調用哪種方法? – schaechtele 2010-04-01 13:45:52

+1

「使用」按鈕(來自內置攝像頭控件)調用上面的UIImagePickerControllerDelegate方法。 我能夠得到這個工作,但只有在移動了「[picker dismissModalViewControllerAnimated:YES];」行到同一方法的頂部。然而,似乎仍有點呆滯。 – wgpubs 2010-04-01 17:15:54

回答

0

今天我有類似的問題。問題是我過度釋放變量。這裏是我的代碼這是崩潰的一部分:

UIImagePickerController *imagePicker = [[[UIImagePickerController alloc]init]autorelease]; 
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
imagePicker.delegate = self; 
[self presentModalViewController:imagePicker animated:YES] 

然後:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    UIImage *image = [[info objectForKey:@"UIImagePickerControllerOriginalImage"]fixOrientation]; 
    [self performSelectorInBackground:@selector(uploadAPhoto:) withObject:image]; 

    [picker release]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 

我所做的是刪除 [選取器版本]的唯一的事; 行,現在它工作得很好。

看你的代碼,我會說,有這一行的一個問題:

picker dismissModalViewControllerAnimated:YES]; 

如果這是它是如何在你的項目,那麼它是真正奇怪的是,它甚至可以運行,還有的缺少「[」在行的開始。我正在使用

[self dismissModalViewControllerAnimated:YES]; 

嘗試使用它。

編輯

對不起,沒看到的問題:)

+2

如果OP在他們的項目中缺少這個括號,它甚至不會編譯。 – 2012-01-10 16:20:39

相關問題