Reputation: 223
I have a function in my appdelegate that is being called when a notification fires off. When this function is called I am hoping to get access to a specific ViewController and manipulate a table cell whether it is the current View or not. I was able to get this to work using the rootViewController method but since it is no longer set as the root view this no longer works.
I am currently using this code:
let stopOption = UIAlertAction(title: "OK", style: .default) {
(action:UIAlertAction)->Void in self.audioPlayer?.stop()
print("Stop index is \(index)")
Alarms.sharedInstance.setEnabled(false, AtIndex: index)
let sb = UIStoryboard(name: "Main", bundle: nil)
let mainVC = sb.instantiateViewController(withIdentifier: "MainVC")
dump(mainVC)
let cells = (mainVC as! MainAlarmViewController).tableView.visibleCells
dump(cells)
for cell in cells
{
if cell.tag == index{
print("Found the cell")
let sw = cell.accessoryView as! UISwitch
sw.setOn(false, animated: false)
}
}
}
The first "dump" statement is returning the correct ViewController but it does not show any of the subViews and the second dump statement returns "- 0 elements".
Any help is massively appreciated.
Upvotes: 0
Views: 87
Reputation: 16456
When this function is called I am hoping to get access to a specific ViewController and manipulate a table cell whether it is the current View or not
For that you need to use Notification
here is example how to use notificatoin http://dev.iachieved.it/iachievedit/notifications-and-userinfo-with-swift-3-0/
you can post notification from AppDelegate
and catch to ViewController
Upvotes: 1