[英]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.