Reloading/Updating UIPickerView data from CoreData when adding a new item in Swift

I have two ViewControllers one of them have a tableView to add items (like app List) and saving them to the CoreData and the other viewController have a textField with inputType of pickerView that get all the item that saved in the CoreDate and shown them successfully .. the problem is when i added a new item to my tableView and going to my pickerView, the last item did not show up and i have to quit the app and open it again to see the last item in my pickerView!

Can anyone know how to reload/update the pickerView ? I tried reloadAllComponents() and did not work >> maybe i did not know where to call it!

1 answer

  • answered 2018-02-13 00:28 cs4alhaider

    I have Solve it like this:

    func textFieldDidBeginEditing(_ textField: UITextField) {
        if textField.isTouchInside == true {
            myMessageName = []
            myMessageText = []
            getSavedMessaged()
        }
    }
    

    I removed everything from my arrays myMessageName and myMessageText to not duplicate the data then I called getSavedMessaged() to get the latest data from my CoreData and only called getSavedMessaged() here and not in my viewDidLoad()