0
我的appdelegate中有一個函數,當通知被觸發時被調用。當這個函數被調用時,我希望能夠訪問特定的ViewController並操作表格單元格,無論它是否是當前的視圖。 我能夠使用rootViewController方法得到這個工作,但由於它不再被設置爲根視圖,所以不再有效。如何與AppDelegate中的特定視圖進行交互?
我目前使用此代碼:
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)
}
}
}
第一個「傾銷」語句返回正確的視圖控制器,但它並沒有表現出任何的子視圖和第二轉儲語句返回「 - 0元」。
任何幫助是大規模讚賞。
您可以訪問視圖 - 控制。但只有在加載主視圖後才能訪問子視圖。 –
調用函數時可以看到什麼控制器? –
我應該補充說,MainAlarmViewController在這個通知到達的時候已經加載,並且不管MainAlarmViewController當前是否可見都不更新單元。 – user1528944