UIAlertView не будет вызывать функцию - PullRequest
0 голосов
/ 27 февраля 2012

У меня есть функция, которая позволяет вам выбирать, как сделать снимок (из галереи или с камеры).Если «контента» нет (вы еще не сделали снимок), то вы можете это сделать.Если у него есть контент (вы уже сделали фотографию), то появляется диалоговое окно с вопросом, уверены ли вы.Я реализовал UIAlertViewDelegate, чтобы я мог сказать, какую кнопку они нажимают.

Моя проблема возникает, когда они нажимают кнопку ОК (индекс кнопки 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 .... и ни один из них не работал.

Ответы [ 3 ]

4 голосов
/ 27 февраля 2012

Попробуйте этот метод ...

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

        if ([alertView tag] == GALLERY)
        {
            [self galleryButtonPressed:mGalleryButton];
        }
        else
        {
            [self cameraButtonPressed:mCameraButton];
        }
    }
}   
0 голосов
/ 27 февраля 2012

Вместо использования двух кнопок. Используйте лист действий.

- (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];
}

- (void) 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 голосов
/ 27 февраля 2012

реализовать этот метод делегата

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
...