UIAlertView:点击警告框外侧的UIAlertView

时间:2013-03-21 05:57:39

标签: iphone objective-c xcode uialertview

嗨,我是Xcode n的新手,Objective-C需要这方面的帮助。 我有一个没有按钮UIAlertView,它点击自己被解雇。但我想只在点击警报框外面没有内部消除它。感谢

 //generating the alertview with no button

 +(void) showAlertNoButtons:(NSString*)title text:(NSString*)text{

    UIAlertView* alertView = [[UIAlertView alloc]
                          initWithTitle:title message:text
                          delegate:self cancelButtonTitle:nil
                          otherButtonTitles:nil];

   UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
                                    initWithTarget:self
                                    action:@selector(dismissAlert:)];

   alertView.delegate=self;
   [alertView addGestureRecognizer:singleTap];
   [alertView setMultipleTouchEnabled:YES];
   [alertView setUserInteractionEnabled:YES];

  [alertView show];
 }
   //
  +(void)dismissAlert:(UITapGestureRecognizer *)gesture
    {
      UIAlertView* alertView =(UIAlertView *)gesture.view;
      [alertView dismissWithClickedButtonIndex:0 animated:YES];

    }

1 个答案:

答案 0 :(得分:2)

您需要致电- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

当您点按其他地方时

这段代码将处理您的点击

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    [self dismissWithClickedButtonIndex:index animated:YES];
}