2013-02-11 67 views
1

我有一個帶有主表視圖和詳細視圖的分割視圖。在我的分割視圖的主視圖的導航欄上,我有一個按鈕,可讓用戶通過imagePicker拍攝圖片。但是當我按下按鈕時,我的程序不斷崩潰。這裏的MasterViewController.m的過程當按鈕被按下時調用:帶有SplitViewController的iPad上的iOS ImagePicker

-(void) takePicture:(id) sender 
{ 

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
{ 
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; 
} 
else 
{ 
    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 
} 

[imagePicker setDelegate:self]; 

//[self presentViewController:imagePicker animated:YES completion:nil]; 

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    UIPopoverController * popOverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 
    [popOverController presentPopoverFromRect:((UIButton *)sender).frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
    //[popOverController presentPopoverFromRect:CGRectMake(700, 1000, 10, 10) inView:self.detailViewController.imageSpace permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

}else { 

    [self presentViewController:imagePicker animated:YES completion:nil]; 
} 

} 

和這裏的錯誤消息:

2013-02-11 09:06:43.975 ImageSplit2[13044:c07] -[UIBarButtonItem frame]: unrecognized selector sent to instance 0x7183d00 
2013-02-11 09:06:43.976 ImageSplit2[13044:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem frame]: unrecognized selector sent to instance 0x7183d00' 

回答

0

sender不是UIButton,它是一個UIBarButtonItem這是不一個視圖,所以它沒有frame屬性。

更改此:

[popOverController presentPopoverFromRect:((UIButton *)sender).frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

到:

[popOverController presentPopoverFromBarButtonItem:(UIBarButtonItem *)sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

邊注:必須如果從照片庫中選擇圖像在iPad上使用酥料餅。但是,將基於相機的圖像選擇器用作全屏視圖控制器是完全有效的。所以,你不妨從改變你的if聲明:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 

到:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && imagePicker.sourceType != UIImagePickerControllerSourceTypeCamera) 
+0

謝謝,這是我需要什麼和第二獎勵,使我的程序會更好。) – DarkCell 2013-02-11 21:21:55

相關問題