UIAlertView在Swift中不起作用

苹果小子

当我迅速运行此代码时,我不知道为什么应用程序会在“ alertView.show()”部分显示断点而终止,请有人帮帮我。

var alertView = UIAlertView(
    title: "Hey",
    message: "Hello",
    delegate: self,
    cancelButtonTitle: "Cancel"
)
alertView.show()
盖·卡隆

从Xcode 6.0 UIAlertView类:

不推荐使用UIAlertView。改用UIAlertController和UIAlertControllerStyleAlert的preferredStyle。

在Swift(iOS 8和OS X 10.10)上,您可以执行以下操作:

var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel, handler:handleCancel))
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in
                println("User click Ok button")
            }))
        self.presentViewController(alert, animated: true, completion: nil)

func handleCancel(alertView: UIAlertAction!)
        {
            println("User click cancel button")
        }

如果要在“ ActionSheet”而不是“ Alert”中使用,则只需更改UIAlertControllerStyle,例如:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

UIAlertView在Swift中不起作用

来自分类Dev

UIAlertView buttonIndex不起作用

来自分类Dev

UIAlertView removeFromSuperview不起作用

来自分类Dev

alertView:(UIAlertView *)alertView方法在Appdelegate中不起作用

来自分类Dev

UIAlertView按钮操作不起作用

来自分类Dev

scheduleLocalNotification在Swift 2.0中不起作用

来自分类Dev

Swift中的可选分配不起作用?

来自分类Dev

UITextField inputView在Swift中不起作用

来自分类Dev

功能在Swift中不起作用

来自分类Dev

在Swift中创建块不起作用

来自分类Dev

perfrmSegueWithIdentifier()在Swift iOS中不起作用

来自分类Dev

presentViewController在Swift中不起作用

来自分类Dev

UIDevice在Swift 2.0中不起作用

来自分类Dev

CoreAudio AudioObjectRemovePropertyListener在Swift中不起作用

来自分类Dev

AVSpeechSynthesizer isSpeaking在Swift中不起作用

来自分类Dev

功能在Swift中不起作用

来自分类Dev

SKTransition在Swift中不起作用

来自分类Dev

perfrmSegueWithIdentifier()在Swift iOS中不起作用

来自分类Dev

.sort在Swift 2.0中不起作用

来自分类Dev

Swift 中的延迟/睡眠不起作用

来自分类Dev

“hasPrefix”在 Swift 中不起作用

来自分类Dev

pushViewController 在 swift 3 中不起作用

来自分类Dev

Swift - UIAlert 在 UICollectionViewCell 中不起作用

来自分类Dev

在uitableview中添加索引在Swift 2.0中不起作用

来自分类Dev

Swift NSCoding不起作用

来自分类Dev

KeyDown不起作用,Swift

来自分类Dev

MPMoviePlayerController不起作用-Swift

来自分类Dev

Swift SequenceType不起作用

来自分类Dev

Swift NSEvent不起作用