我试图处理一个代码,当用户触摸" ADD TO CART"按钮,当用户触摸"查看订单时,当前显示的信息将显示在警告消息中。按钮。我已经尝试过这个问题(How to save local data in a Swift app?)的答案,但我发现它对我不起作用,从那以后我一直被卡住了。
编辑:在这台计算机上没有xcode,所以我只是在画面上制作了屏幕。
答案 0 :(得分:0)
将以下代码用于警报视图控制器:
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:{})
我希望这对你有所帮助。
答案 1 :(得分:0)
尝试使用此代码完全正常。
您的第一次警告
let message = "BRAND : BRNAD \n MODEL : MODEL \n PRICE : 25$"
let alertController = UIAlertController(
title: "", // This gets overridden below.
message: message,
preferredStyle: .Alert
)
let okAction = UIAlertAction(title: "OK", style: .Cancel) { _ -> Void in
}
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
你的第二次警告......
let message = "BRAND : BRNAD \n MODEL : MODEL \n PRICE : 25$ \n\n\n BRAND : BRAND \n MODEL : MODEL \n PRICE : 120$ \n"
let alertController = UIAlertController(
title: "", // This gets overridden below.
message: message,
preferredStyle: .Alert
)
let okAction = UIAlertAction(title: "OK", style: .Cancel) { _ -> Void in
}
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)