加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 多个UIAlertView问题

发布时间:2020-12-14 18:10:42 所属栏目:百科 来源:网络整理
导读:我的代码有问题,我有两个UIAlertViews代码块,一个带取消和ok按钮,另一个带UI ImagePicker -(IBAction)publicaPeticion { if([txtPeticion hasText] ) { UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"Confirmación de Compra" message:@"Des
我的代码有问题,我有两个UIAlertViews代码块,一个带取消和ok按钮,另一个带UI ImagePicker

-(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之间

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


}

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

-(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”按钮(OK)时,它会将我从照片库中上传图片…

也许是一个有点傻的问题,但我怎么能区分它?

解决方法

几种方式.

1)

看看如何调用委托方法?

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

从alertView参数中,您可以确定调用哪个警报(如果您将cargaImagen和publicaPeticion的警报视图设置为单独的实例变量).

2)

您可以做的另一件事(也可能更容易)是在alertView上设置标签属性.

在您的’cargaImagen’方法中以及创建UIAlert之后,通过alert.tag = 1;将标记设置为1.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读