Mil*_*tle 4 uiview ios swift uialertcontroller
Swift的新手.下面的代码执行没有错误,但在控制台中它显示一条消息.这是一条错误消息以及如何修复它?是否需要在发送应用程序进行审核时修复.
谢谢
这是我的App结构:
VC(1) --> goto --> VC(2)
在VC(1)中,我有:
我创建了一个VC的链接(2):控制 - 拖动BtnGo到VC(2)
我将segue命名为:SegueToVC2
我想做什么:
我需要将一个字符串传递给VC2.在通过之前检查用户是否做出选择.
在PrepareForSegue中,
override func PrepareForSegue(segue:UIStoryboardSegue, sender: AnyObject!) {
var strchk: String = UIlabelMsg.text!
if strchk.isEmpty {
var alert = UIAlertController(title: "Alert",message:" No Selection made",
preferredStyle: UIAlertControllerStyle.Alert)
alert.AddAction(UIAlertction(title: "OK",style:UIAlertActionStyle.Default,hanlder: nil))
self.presentViewController(alert, animated: true, completion: nil )
} else {
if (segue.Identifier =="SegueToVC2") {
var targetVC = segue.destinationViewControl as! VC2
targetVC.strMsg = UILabelMsg.text
}
}
Run Code Online (Sandbox Code Playgroud)
问题:
在控制台中,它显示了这个:
UIView:0x7fdfc25668c0; frame =(0,0,375,667); autoresize = w + h; layer =的窗口不等于View的窗口!
我有这些问题
为什么我使用时不需要为BtnGo编写代码prepareForSegue?如果我有超过2个按钮?这两个将由Segue处理?
UIView没有presentViewController方法,有什么用self?你可以使用窗口UIView来呈现.
var alert = UIAlertController(title: "Alert",message:" No Selection made",
preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK",style:UIAlertActionStyle.Default,handler: nil))
self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
编辑:可能你需要覆盖shouldPerformSegueWithIdentifier以检查UIlabelMsg.text.
override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
var strchk: String = UIlabelMsg.text!
if strchk.isEmpty {
var alert = UIAlertController(title: "Alert",message:" No Selection made",
preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK",style:UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
return false
} else {
return true
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5124 次 |
| 最近记录: |