ios开发弹框提示(适配系统7,8,9)

来源:互联网 发布:js encodeuri 编辑:程序博客网 时间:2024/06/03 20:46


首先在基类的控制器定义以下属性

@property (copy, nonatomic) void(^cancleBlock)();/**<取消点击事件 */

@property (copy, nonatomic) void(^enSureBlock)();/**<确定点击事件 */


在基类的控制器中写入以下方法

#pragma mark --弹框提示--


/** 没有点击事件 */

-(void)showAlertVCContentWithoutEvent:(NSString*)content

{

    NSLog(@"systemVersion-%f",[UIDevicecurrentDevice].systemVersion.floatValue );

    if ([UIDevicecurrentDevice].systemVersion.floatValue >=8.0) {

        

        NSLog(@"8.0以上");

        UIAlertController* alertVC = [UIAlertControlleralertControllerWithTitle:@"温馨提示"message:content preferredStyle:UIAlertControllerStyleAlert];

        [alertVC addAction:[UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *_Nonnull action) {

        }]];

        

        [selfpresentViewController:alertVC animated:YEScompletion:nil];

    }

    else{

        UIAlertView* alertView = [[UIAlertViewalloc]initWithTitle:@"温馨提示"message:content delegate:nilcancelButtonTitle:nilotherButtonTitles:@"确定",nil];

        [alertView show];

        NSLog(@"8.0以下");

    }

    

}


/** 有点击事件 */

-(void)showAlertVCContent:(NSString*)content cancleBlock:(void (^)())cancleBlock enSureBlock:(void (^)())enSureBlock

{

    NSLog(@"systemVersion-%f",[UIDevicecurrentDevice].systemVersion.floatValue );

    self.cancleBlock = cancleBlock;

    self.enSureBlock = enSureBlock;

    if ([UIDevicecurrentDevice].systemVersion.floatValue >=8.0)

    {

        NSLog(@"8.0以上");

        UIAlertController* alertVC = [UIAlertControlleralertControllerWithTitle:@"温馨提示"message:nilpreferredStyle:UIAlertControllerStyleAlert];

        [alertVC addAction:[UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *_Nonnull action) {

            

            if (self.enSureBlock) {

                self.enSureBlock();

            }

            

        }]];

        

        [alertVC addAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *_Nonnull action) {

            if (self.cancleBlock) {

                self.cancleBlock();

            }

        }]];

        

        [selfpresentViewController:alertVC animated:YEScompletion:nil];

    }

    else{

        NSLog(@"8.0以下");

        UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"温馨提示"message:content delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

        [alert show];

    }

    

    

    

}


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

{

    switch (buttonIndex)

    {

        case 0:

            if (self.cancleBlock)

            {

                self.cancleBlock();

            }

            

            break;

        case 1:

            if (self.enSureBlock)

            {

                self.enSureBlock();

            }

        default:

            break;

    }

}


外部调用方法

/** 没有点击事件 */

-(void)showAlertVCContentWithoutEvent:(NSString*)content;


/** 有点击事件 */

-(void)showAlertVCContent:(NSString*)content cancleBlock:(void (^)())cancleBlock enSureBlock:(void (^)())enSureBlock;

以上就是完成了弹框事件,并且可以根据相应的点击做出处理
0 0
原创粉丝点击