iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 多个UIAlertView问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我的代码有问题,我有两个UIAlertViews代码块,一个带取消和ok按钮,另一个带UI ImagePicker -(IBACtion)publicaPeticion { if([txtPeticion hasText] ) { UIAlertView *alerta = [[UIAlertView alloc]
@H_675_18@ 我的代码有问题,我有两个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.

大佬总结

以上是大佬教程为你收集整理的ios – 多个UIAlertView问题全部内容,希望文章能够帮你解决ios – 多个UIAlertView问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。