2015-11-25 40 views
0

我有一个很奇怪的问题,我想在用户点击取消按钮或其他任何地方时关闭UIAlertView。我已经阅读了几乎所有的帖子,找不到解决我的问题的答案,你们中的任何人都不知道如何做到这一点?请引导我完成这些步骤,我将非常感谢。关闭iOS中的alert视图,点击外部或取消按钮

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:label.text 
               message:label1.text 
               delegate:self 
             cancelButtonTitle:@"ཕྱིར་འཐེན།" 
             otherButtonTitles:@"ཉེ་ཆར།",@"དགའ་མོས།",@"ཉེ་ཆར་གཙང་བཟོ།",@"དགའ་མོས་གཙང་བཟོ།",nil]; 
[alert show]; 

回答

0

调用touchesEnded方法。它会帮助您关闭alertView当用户水龙头其他地方的屏幕

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 
    [self.yourAlert dismissWithClickedButtonIndex:0 animated:YES]; 
} 

并记住创建yourAlert为强引用

+0

我相信这种方式,如果您单击是而不是取消,您将2点击是和取消两个事件... –

0

试试这个代码

// Add gesture 
UITapGestureRecognizer *tapOnView = [[UITapGestureRecognizer alloc] initWithTarget:self 
                      action:@selector(dismissAlert)]; 
[alert addGestureRecognizer:tapOnView]; 

然后,你可以调用一个函数即解除您的警报

相关问题