2012-02-27 21 views
0

私はギャラリーからまたはカメラから写真を撮る方法を選択できるようにする機能があります。 「コンテンツ」がない場合(既に写真を撮っていない場合)、自由に行うことができます。コンテンツを持っている場合(既に写真を撮っている場合)、ダイアログボックスが表示され、あなたが確信しているかどうかを尋ねます。 UIAlertViewDelegateを実装して、どのボタンが押されたかを知ることができます。UIAlertViewコール機能がありません

私の問題はOK(ボタンインデックス0)を押しても機能しない(呼び出されて、デバッガで処理される)という問題が発生します。もう一度ボタンを押すと別のダイアログボックスが表示されません。

私は問題が何であるか分かりません。私はGoogleに何を試してみるか考えません。

ご協力いただきありがとうございます。

-(IBAction)galleryButtonPressed:(id)sender 
{ 
    if (!mHasContent) 
    { 
     [mDelegate performSelector:@selector(galleryButtonPressed:) withObject:self]; 
    } 
    else 
    { 
     UIAlertView* warning = [[UIAlertView alloc] initWithTitle:@"Section Complete" message:@"You have already taken an image. Selecting another will overwrite it, you can select to take another image above. Are you sure you wish to continue?" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: @"Cancel", nil]; 

     [warning setTag:GALLERY]; 
     [warning show]; 
     [warning release]; 
    } 
} 

-(IBAction)cameraButtonPressed:(id)sender 
{ 
    if (!mHasContent) 
    { 
     [mDelegate performSelector:@selector(captureImageButtonPressed:) withObject:self]; 
    } 
    else 
    { 
     UIAlertView* warning = [[UIAlertView alloc] initWithTitle:@"Section Complete" message:@"You have already taken an image. Selecting another will overwrite it, you can select to take another image above. Are you sure you wish to continue?" delegate:self cancelButtonTitle:nil otherButtonTitles: @"OK", @"Cancel", nil]; 

     [warning setTag:CAMERA]; 
     [warning show]; 
     [warning release]; 
    } 
} 

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    // If they selected OK then resend the event to take a photo or select from the gallery 
    if (buttonIndex == 0) 
    { 
     mHasContent = NO; 

     if ([alertView tag] == GALLERY) 
     { 
      [self galleryButtonPressed:mGalleryButton]; 
     } 
     else 
     { 
      [self cameraButtonPressed:mCameraButton]; 
     } 
    } 
} 

私はまたのonClickとwillDismiss ....でこれを試してみましたが、それらのどれもどちらか働きました。

答えて

0

は、このデリゲートメソッド

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
+0

申し訳ありませんが、私は言っていたはずです。私はすでにそれを試してきましたし、 "willDissWithButtonIndex"でもあり、どちらもうまくいきませんでした。 – Luke

4

actionsheetを使用してください。.. ...代わりに二つのボタンを使用しての

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 0) 
    { 
     mHasContent = NO; 

     if ([alertView tag] == GALLERY) 
     { 
      [self galleryButtonPressed:mGalleryButton]; 
     } 
     else 
     { 
      [self cameraButtonPressed:mCameraButton]; 
     } 
    } 
} 
+0

"Gallary"& "CAMERA"の値は何ですか?それはintまたは文字列です – Rupesh

+0

#defineギャラリー1を定義する #define CAMERA 0 – Luke

+0

ローカルのint temp = alertview.tagでalertview.tagの値を取得し、その値をCAMERA/GALLERYと比較してください – Rupesh

0

を、この方法を試してみてくださいを実装します。

- (IBAction)takePic:(ID)、送信者 {

GroceryApplicationAppDelegate *appDelegate = (GroceryApplicationAppDelegate*)[[UIApplication sharedApplication]delegate]; 

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo",@"Choose Existing Photo",nil]; 
[sheet setDelegate:self]; 
[sheet showInView:appDelegate.window]; 
[sheet release]; 
} 

- (ボイド)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

if(buttonIndex == 0) 
{ 

    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"No Camera Found" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 

     return; 
    } 

    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 

    [self presentModalViewController:picker animated:YES]; 
} 

if (buttonIndex == 1) 
{ 

    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 

    [self presentModalViewController:picker animated:YES]; 
} 

}

+0

このコードを変更して、プロジェクトに従って使用することができます。 – Rupesh

+0

疑問がある場合は私に尋ねてください – Rupesh

関連する問題