我正在尝试编写一个代码,当用户触摸“添加到购物车”按钮时,当前显示的信息将在用户触摸“查看订单”按钮时显示在警报消息中。我已经尝试过这个问题的答案( How to save local data in a Swift app? ),但我发现它对我不起作用,从那以后我就一直被困住了。
编辑:这台计算机上没有 xcode,所以我只是用 Paint 制作了屏幕。
最佳答案
使用以下代码作为警报 View Controller :
let alertController = UIAlertController(title: "\n", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let margin:CGFloat = 8.0
let rect = CGRectMake(margin, margin, alertController.view.bounds.size.width - margin * 4.0, 100.0)
let customView = UITextView(frame: rect)
customView.text = "OREDERTEXT\nOREDERTEXT"
customView.backgroundColor = UIColor.clearColor()
customView.font = UIFont(name: "Helvetica", size: 15)
alertController.view.addSubview(customView)
let somethingAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in print("something")
print(customView.text)
})
alertController.addAction(somethingAction)
self.presentViewController(alertController, animated: true, completion:{})
希望这对您有帮助。
关于ios - 如何在按下按钮后将 View 中的特定信息添加到警报消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39958049/