触摸侧面活动表时如何解除操作表?

时间:2014-06-06 14:35:51

标签: cocoa-touch uiactionsheet

我使用以下方法以编程方式使用动作表与xcode 6,但我没有想法显示和解雇它,任何人都帮助我...

var actionSheet = UIAlertController(title: "Title Text", message: "Message Text", preferredStyle: UIAlertControllerStyle.Alert)

 actionSheet.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))

 self.presentViewController(actionSheet, animated: true, completion: nil)

1 个答案:

答案 0 :(得分:-2)

这将允许用户取消警报。我不太确定如何允许用户点击模态之外的任何地方。您可以在基本视图上使用点击手势识别器,但我认为模态可能会窃取这些触摸。

这应该有助于您开始正确的轨道。

let alertController = UIAlertController(title: "Select action", message: nil, preferredStyle: UIAlertControllerStyle.Alert)

// First action
let firstAction = UIAlertAction(title: "First action", style: UIAlertActionStyle.Default, handler: {
  (alertAction: UIAlertAction!) in
    println("First action selected")
})

// Cancel action
let cancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (alertAction: UIAlertAction!) in
  alertController.dismissViewControllerAnimated(true, completion: nil)
})

alertController.addAction(firstAction)
alertController.addAction(cancel)

self.presentViewController(alertController, animated: true, completion: nil)