2

こんにちは私はXcodenobjectiveに不慣れです-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];

    }
4

1 に答える 1

2

あなたは電話する必要があります- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

他の場所をタップすると

このコードはタップを処理します

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    [self dismissWithClickedButtonIndex:index animated:YES];
}
于 2013-03-21T06:00:23.193 に答える