2012-10-15 102 views
1

當我嘗試從xcode 4.5調用相冊時,應用程序崩潰。 注意:我將應用程序方向設置爲橫向模式。在你的邏輯崩潰在self.view presentviewcontroller:UIImagePickerController在iOS 6

UIImagePickerController *picker=nil; 
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) 
{ 
    picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    picker.allowsEditing = NO; 
    picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: 
      UIImagePickerControllerSourceTypeSavedPhotosAlbum]; 

} 

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    [self presentViewController:picker animated:YES completion:nil]; 
} 
+0

該代碼位於視圖控制器中? –

+0

什麼是異常/錯誤/崩潰的樣子? –

+0

你能更具體嗎?當第二個陳述達成時,你如何確信第一個陳述是真實的?當你打電話給presentViewController :::你怎麼能確定picker不是零? –

回答

1

的一個錯誤是,如果isSourceTypeAvailable;否在iPhone上,你會嘗試提出一個控制器,這是nil