簡體   English   中英

Swift-TVOS取消UIAlertController

[英]Swift-tvOS dismissing UIAlertController

我正在為tvOS做應用,我在取消UIAlertController問題。 我在普通的UIViewController上展示一個UIAlertController 當我按下電視遙控器上的“菜單”按鈕以消除警報時,父視圖控制器首先被解除,而當我第二次按下菜單按鈕時, UIAlertController正確消失,但是在父視圖控制器之后,我不想關閉它。

func showTextDescription(message:String?) {
    let allertController=UIAlertController(title: title, message: message, preferredStyle: .ActionSheet)

    // Cancel action (is invisible, but enables escape)
    allertController.addAction(UIAlertAction(title: nil, style: .Cancel, handler: nil))

    self.presentViewController(allertController, animated: true, completion: nil)
    }

我怎樣才能只關閉alertcontroller 謝謝。

要關閉警報控制器,只需調用此行代碼即可。

allertController.dismissViewControllerAnimated(true, completion: nil)

或者,您可以添加警報措施。

let alertAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
allertController.addAction(alertAction)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM