I thought I was following everything step by step. I am getting no errors, but when I click the i icon to Edit an item, the Checklist Item to be edited does not load in the text field. It is always blank.
override func viewDidLoad() {
super.viewDidLoad()
if let item = itemToEdit {
title = "Edit Item"
textField.text = item.text
doneBarButton.isEnabled = true
}
}
I know the code block is running because the title is changing to Edit Item and the doneBarButton is enabled when I type text. I used File Merge and could not find any significant differences. The code block below is the only thing responsible for loading the something in the textfield right?
I have cleaned the Build Folder, Deleted Derived Data Folder, Restarted Xcode and still nothing.
Have you tried setting a breakpoint on the line where the item text is loaded, or printing the item text to the console at that point to see if the item has any text to be loaded?
If everything is working correctly, then my guess would be that either item.text is empty or that something else is overwriting the value in the text field. But without seeing what you’re seeing, it’s hard to know what is going on.
If you still can’t figure it out, please upload your project as a ZIP file somewhere and provide a link to the ZIP file so that I (or someone else) can download the file and see what might be going on.
The zip works, except it is missing the enclosing “Checklists” folder, but that can be fixed up.
After some tracing and head scratching, I figured out that in the storyboard, the Text Field has the “Clear when editing begins” checkbox checked. As a result, it clears the text when editing begins.