多个UIAlertView问题 [英] multiple UIAlertView issue

查看:52
本文介绍了多个UIAlertView问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题,我有两个UIAlertViews代码块,一个带取消和ok按钮,另一个带UIImagePicker

I have an issue with my code, I have two blocks of code of UIAlertViews one with cancel and ok button, and the other to make a UIImagePicker

-(IBAction)publicaPeticion
 {
    if([txtPeticion hasText] )
    {

        UIAlertView *alerta = [[UIAlertView alloc]
                              initWithTitle:@"Confirmación de Compra" 
                              message:@"Deseas comprar la petición por $12.00" 
                              delegate:self 
                              cancelButtonTitle:@"Cancelar"
                              otherButtonTitles:@"Aceptar", nil];
        [alerta show];  
    }


}

问题是在publicaPeticion和cargaImagen之间

The issue is between publicaPeticion and cargaImagen

-(IBAction)cargaImagen
{

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Subir una imagen" 
                          message:@"¿De donde deseas subir una imagen?" 
                          delegate:self 
                          cancelButtonTitle:@"Cancelar" 
                          otherButtonTitles:@"Desde el equipo",@"Tomar con camara", nil];
    [alert show];


}

以及我获取源的方法图像,来自照片流或来自相机

and also my method to get the source of the image, from the photo stream or from the camera

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 1)
    {
        picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];

    }
    if(buttonIndex ==2)
    {
        picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentModalViewController:picker animated:YES];
    }
}

问题是,当我按下Aceptar时按钮(好),它带我到照片库中的上传图片...

the question is, that when i press "Aceptar" button (OK), it takes me to the upload picture from the photo library...

这个问题可能有点傻但是我怎么能区分它呢? / p>

maybe is a little bit silly the question but how can I differentiate it?

推荐答案

有几种方式。

1)

了解如何调用委托方法?

See how the delegate method is called?

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

来自 alertView 参数,您可以告诉调用哪个警报(如果您将cargaImagen和publicaPeticion的警报视图设置为单独的实例变量)。

From the alertView parameter, you can tell which alert did the calling (if you set cargaImagen and publicaPeticion's alertviews to separate instance variables).

2)

你可以做的另一件事(也许更容易)是在alertView上设置一个标签属性。

Another (and probably easier) thing you could do is to set a tag property on your alertView.

在你的'cargaImagen'方法中以及创建UIAlert之后,通过 alert.tag = 1;

In your 'cargaImagen' method and right after you create the UIAlert, set the tag to 1 via alert.tag = 1;.

然后,在 alertView:clickedButtonAtIndex:委托方法,当 alertView.tag = = 1 ,你会知道它来自cargaImagen,如果它是2(或零),你知道它来自publicaPeticion。

Then, in your alertView:clickedButtonAtIndex: delegate method, when alertView.tag == 1, you'll know it comes from cargaImagen and if it's 2 (or zero), you know it comes from publicaPeticion.

这篇关于多个UIAlertView问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆