Over the last couple of days I have been trying to figure out how I can update a tableViewCell from TableView controller and it's giving me hard time. Here is where I have reached thus far:
Creating a timer
I set the time for the reminder in editVC(which you accessed by tapping on the tableViewCell). There you can set the time and the reminder is made. Every task has sSelectedDate
which is the date set by the user.
This is what I think I should do next: Send this sSelectedDate
to the firstViewController(where the tableView resides) and use this date to create a timer in the firstVC.
Question: What is the correct way of sending the particular date from the task to firstVC?
timesUpTimer = Timer(fireAt: selectedDate, interval: 0, target: self, selector: #selector(updateTimeLabel), userInfo: ["taskID": EditNotes], repeats: false)
UserInfo Dilemma
The "taskID" I am sending can be a uniqueTaskID I can generate with each task when a reminder is created. EditNotes
is the class
of NSManagedObject
for CoreData.
Question: What's the correct way of sending the uniqueTaskID to the firstViewController?
Selector Method
@objc func updateTimeLabel(_ timer: Timer)
{
let userInfo = timer.userInfo as Dictionary<String, AnyObject>
var task = userinfo["taskID"] as EditNotes
task.belliconcolor = .white
// do stuff with task object
}
Since I am changing the coreData here I hope FetchedResultsController method is triggered and the tableView is updated.
This is the method invoked when a timer is up.
Question: Should I only rely on FRC or should I actually update the corresponding row in tableview? If yes then how?
Should I create Array for timers
This timer I create in the firstVC is for just one task? Do I have to create an array of timers and save it in coreData also?
Question: How to do it?
TLDR: How to create timers/array of timers for every element/task of the tableview that when invoked updates the corresponding row in the tableview?