ios - 如何在按下按钮后将 View 中的特定信息添加到警报消息?

标签 ios swift

Main screen

我正在尝试编写一个代码,当用户触摸“添加到购物车”按钮时,当前显示的信息将在用户触摸“查看订单”按钮时显示在警报消息中。我已经尝试过这个问题的答案( How to save local data in a Swift app? ),但我发现它对我不起作用,从那以后我就一直被困住了。

"VIEW ORDERS" button's alert screen (left side). Alert screen after adding another item to cart (right side)

编辑:这台计算机上没有 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/

相关文章:

arrays - 在 Swift 中归档和取消归档 DocumentDirectory 中的数组

iOS UI 测试 iMessage 应用程序/扩展

ios - 从生成的 swagger 代码中使用 swift 客户端发布图像

ios - 在 react-native 中打开键盘时,ScrollView 无法滚动到底部。 [IOS]

ios - UITextField attributedPlaceholder 无效

swift - 扩展 UILabel 以删除上升部分?

iphone - 如何以编程方式在 iOS 中获取 iPhone 蓝牙适配器名称

ios - 如何监听 ObservableObject

objective-c - objective-c 和 swift 中的不同格式掩码

ios - 如何从 UIDocumentPicker 获取正确的文件名,didPickDocumentsAt urls : [URL]