しばらくしてからボタンなしのuialertviewを却下する方法はありますか?

StackOverflow https://stackoverflow.com/questions/4192574

質問

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"tittle"
               message:@""
                 delegate:self
              cancelButtonTitle:@""
              otherButtonTitles:nil];
  [alertView show];
  [alertView release];

Alerviewがしばらく表示された後、Alerviewを暗くしたいのですが、AlertViewにボタンがない場合、呼び出しても機能しません -dismissWithClickedButtonIndex:animated: methodと-performSelector:withObject:afterDelay:それを却下する他の方法はありますか?アイデアをありがとう!

役に立ちましたか?

解決

-(void)xx  {
     [self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}

それだけです。私はそれを修正します

他のヒント

10秒の遅延を使用して却下します

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [alertController dismissViewControllerAnimated:YES completion:^{
        p\Perform Action after dismiss alertViewController
    }];
});

xamarin.ios / monotouchでは、これは私のために働きました:

private async Task ShowToast(string message, UIAlertView toast = null)
    {
        if (null == toast)
        {
            toast = new UIAlertView(null, message, null, null, null);
            toast.Show();
            await Task.Delay(2000);
            await ShowToast(message, toast);
            return;
        }

        UIView.BeginAnimations("");
        toast.Alpha = 0;
        UIView.CommitAnimations();
        toast.DismissWithClickedButtonIndex(0, true);
    }

バックグラウンドスレッド(メインのUIスレッドではない)から非同期メソッドが呼び出された場合は、InvokeOnMainThreadが引き続き必要であることを忘れないでください。これは、次のような上記の方法を呼び出すことを意味します。

 BeginInvokeOnMainThread(() =>
 {
   ShowToast(message);
 });

上記の回答を更新します UIAlertViewdeprecated このリンクで答えてください

2番目の関数は次のようにする必要があります

-(void)dismissAlertView:(UIAlertController *)alertView{

  [alertView dismissViewControllerAnimated:YES completion:nil];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top