是否可以获取 UIView 及其内容(标签、文本字段和按钮)并在运行后复制并添加其主视图?
我在应用程序中创建了一个表单,用户可以添加他们访问过的地点。由于应用程序不知道用户事先去了多少个地方,我希望 UIView 保存地点信息以具有加号按钮,以便在按下时,它将复制这些字段以允许用户输入下一个地点(就像在网络表单上一样)。
如果您知道资源,请也告诉我!我们将不胜感激!
最佳答案
我最终将表单字段转换为 UIViewTable。
每个单元格都有一个添加按钮和删除按钮,它们与添加和删除功能连接在一起:
cell?.removeButton.tag = indexPath.row
cell?.removeButton.addTarget(self, action: "removeEntry:", forControlEvents: .TouchUpInside)
cell?.addButton.addTarget(self, action: "addEntry:", forControlEvents: .TouchUpInside)
每个函数如下所示:
func removeEntry(sender: UIButton!) {
println("removed entry field")
self.places.removeAtIndex(sender.tag)
self.addresses.removeAtIndex(sender.tag)
self.reviews.removeAtIndex(sender.tag)
tableView.reloadData()
}
func addEntry(sender: UIButton!) {
println("added entry field")
self.places.append("")
self.addresses.append("")
self.reviews.append("")
tableView.reloadData()
}
关于ios - 在 iOS 中复制和添加 View 和内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31256428/