[英]Saving text in UITextView Swift 3
我正在IOS平台Swift 3上创建一个待办事项应用程序,我试图将注释保存在UITextView中,以便在我回击或终止应用程序时保存数据。
StoryBoard在导航栏上有一个UITextView和一个保存按钮如何使用户在UITextView中输入其文本并保存
class Details: UIViewController, UITextViewDelegate{
// MARK: - IB
@IBOutlet weak var noteText: UITextView!
@IBAction func addNote(_ sender: UIButton) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let addNote = Note(context: context)
addNote.details = noteText.text!
//Saving
(UIApplication.shared.delegate as! AppDelegate).saveContext()
}
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var Notes: [Note] = []
func getData() {
do {
Notes = try context.fetch(Note.fetchRequest())
} catch {
print("Fetching Failed")
}
}
override func viewWillAppear(_ animated: Bool) {
getData()
}
override func viewDidLoad() {
super.viewDidLoad()
let MyIcon = UIImageView(image: UIImage(named: "037_Pen"))
self.navigationItem.titleView = MyIcon
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
知道如何显示吗?
创建的名为Note
Entity
Attribute
details
为String
类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.