While I am pretty sure of a simple solution to this issue, the issue here is that the secondVC is in no way or form separate from the firstVC. The secondVC is what you get when you tap on the tableViewCell. The cell you tapped (using the indexPath) I send some data to the secondVC and then you can edit that task in the secondVC and even set a notification reminder for it.
In the secondVC I am running some code that triggers a timer at the time set by the user for that particular task. The timer in return invokes a selector method that updates a label and changes it to "Time's Up".
When this label is "Time's Up", I set the bellicon which is in the tableviewcell in the firstVC to white or remove the bellicon from the particular task.
I want this peice of code to run even if I am not in the secondVC. (I have this code running in viewDidAppear). If I put this code in a function and then call it while I am in the firstVC, the code has no idea which time it should select.
override func viewWillAppear(_ animated: Bool) {
adjustTextViewHeight()
edittaskview.becomeFirstResponder()
cardremindery?.constant = -999
guard let selectedDate = editnotes?.sSelectedDate,
var needsToRemind = editnotes?.sReminderState else {
print("No date selected")
return
}
if (needsToRemind) {
self.timesUpTimer = Timer(fireAt: selectedDate, interval: 0, target: self, selector: #selector(updateTimeLabel), userInfo: nil, repeats: false)
RunLoop.main.add(timesUpTimer!, forMode: RunLoopMode.commonModes)
}
}
Selector code that updates the belliconcolor:
@objc func updateTimeLabel()
{
editnotes?.sReminderDate = "Time's up"
editnotes?.belliconcolor = .white
reminderMsg.text = editnotes?.sReminderDate
print("Time is up ok")
}
The above code works when you are in the secondVC. I want this to work even if I am in the firstVC. Since I am using FetchedResultsController, I am pretty sure that the tableView will be updated if data is changed and since the belliconcolor is an element I have saved in coreData changing it will update the tableview.
The question is: How can I run this piece of code from the firstVC for all the elements of the tableview?
The bellicon appear next to those tasks that you set reminder for in the secondVC. You access secondVC by tapping the relevant cell in the tableview:
You set the reminder in this secondVC. If the the time is up then the label underneath Due Date changes to 'Time's Up' and the belliconcolor for the specific task is changed to .white
Time's Up! -> The piece of code has been excecuted and the belliconcolor for this particular task is .white. This will be apparent when I go to the firstVC. I want this code to run even if I am in the firstVC so that the tableview is automatically updated.