iOS之修改项目BUG之旅--(三)

问题:在一个图片浏览器放大当前图片的时候,点击删除,出现提示框是否删除图片
解决方案:
一.使用UIAlertView解决(ps:这是ios8以前的方法)

//点击事件
- (void)photoBrowserButtons:(CHPhotoBrowserButtons *)buttons deleteBtn:(UIButton *)deleteBtn {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你确定要删除照片吗?" delegate:self   cancelButtonTitle:@"取消" otherButtonTitles: @"确定",nil];

[alert show];
}
//UIAlertViewDelegate协议实现的方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [CHPhotoScrollHttpTool   deletedFamilyPhoto:self.photos[self.currentPhotoIndex]                                        success:^{                                                [MBProgressHUD showSuccess:nil];                                                [[NSNotificationCenter defaultCenter]  postNotificationName:NOTIFICATION_DIDDETLE_PIC object:nil];                                               [self mcancel:nil];                                                                                         }                                          
 failure:^{                                              [MBProgressHUD showError:nil];                                              [self mcancel:nil]; }];
[buttonsView hide];
isShow = NO;
    }
}

二.使用UIAlertController(ps:ios8以后使用的方法)

//点击事件
- (void)photoBrowserButtons:(CHPhotoBrowserButtons *)buttons deleteBtn:(UIButton *)deleteBtn {
//创建UIAlertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"你确定要删除照片吗?" preferredStyle:(UIAlertControllerStyleAlert)];
//创建确定按钮
    UIAlertAction *defult = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * action) {
     NSLog(@"点击确定后执行的事件");
        }];
//创建取消按钮 
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
//将UIAlertAction添加到UIALertController 
    [alertController addAction:defult];
    [alertController addAction:cancel];
//获取当前ViewController,并present弹出模态UIAlertController
//注意,这里presentViewController前面的对象必须为ViewController
    [[self getPresentedViewController] presentViewController:alertController animated:YES completion:nil];
    }
//获取当前屏幕中present出来的Viewcontroller
- (UIViewController *)getPresentedViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    if (topVC.childViewControllers.count>0) {
        topVC = [topVC.childViewControllers lastObject];
    }

    return topVC;
}

你可能感兴趣的:(bug,界面,uialert)