2012-03-26 10 views
1

UIImagePickerControllerを使用して、iPhone/iPadでユーザーの写真から写真を取得しようとしています。このコードはiPhoneでうまく動作しますが、iPadで実行すると、デバッガは "キャッチされていない例外 'NSGenericException'の理由でアプリを終了しています。理由: ' - [UIPopoverController dealloc]私はObjective-Cをとても新しくしているので、これを引き起こしていることが分かりません。何も解除しないで、ARCをオンにしました。ここに私のコードは次のとおりです。 ViewController.mUIPopoverControllerで奇妙なエラーが発生する

#import "PhotoViewController.h" 


@implementation PhotoViewController 
@synthesize grabButton; 
@synthesize image; 
@synthesize imgPicker; 

- (IBAction)grabImage { 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
     UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker]; 
     [popover presentPopoverFromRect:self.image.bounds inView:self.image permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

    } else { 
     [self presentModalViewController:imgPicker animated:YES]; 
    } 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo { 
    image.image = img; 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 

- (void)viewDidLoad 
{ 
    self.imgPicker = [[UIImagePickerController alloc] init]; 
    self.imgPicker.allowsImageEditing = YES; 
    self.imgPicker.delegate = self; 
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

} 
+0

可能なデュープます。http :/ /stackoverflow.com/questions/8895071/uipopovercontroller-dealloc-reached-while-popover-is-still-visible – CodaFi

+0

投稿前にそれを見ましたが、残念ながら助けにはなりませんでした。 –

答えて

3

UIPopoverは、オブジェクトの醜いパッチワーク獣です。 Deallocが時期尚早に到達しないようにするには、強固な財産とiVarでなければなりません。これと同様の.hでこれを追加します。

@interface MyClass: NSObject { 
    UIPopover *_popover; 
} 
@property (nonatomic, strong) UIPopover * popover; 

//.m 

@synthesize popover = _popover; 

あなたはポップオーバーをインスタンス化すると、プロパティまたはインスタンスに割り当て:

self.popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker]; 

または

_popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker]; 
+0

ありがとう!どのクラスを削除すべきですか?申し訳ありませんが、私はプログラミングの初心者です。また、上記の変更のすべてを追加しましたが、同じエラーがまだ発生しています。 –

+0

プロパティまたはiVarsを追加するとき(前述のように)、競合する名前のiVarsを削除する必要があります。そうしないと、.hで宣言したiVarを覆い隠します。 .mファイルから、UIPopover(オブジェクトではなく単語)の言及を削除してください。 – CodaFi

+0

すごく、ありがとう! –

関連する問題