gpt4 book ai didi

ios - 我如何与 AppDelegate 的特定 View 进行交互?

转载 作者:行者123 更新时间:2023-11-28 15:54:17 25 4
gpt4 key购买 nike

我的 appdelegate 中有一个函数,它在通知触发时被调用。调用此函数时,我希望能够访问特定的 ViewController 并操作表格单元格,无论它是否是当前 View 。我能够使用 rootViewController 方法让它工作,但因为它不再设置为 Root View ,所以它不再有效。

我目前正在使用这段代码:

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)
}
}
}

第一个“转储”语句返回正确的 ViewController,但它不显示任何 subview ,第二个转储语句返回“- 0 个元素”。

非常感谢任何帮助。

最佳答案

调用此函数时,我希望能够访问特定的 ViewController 并操作表格单元格,无论它是否是当前 View

为此你需要使用Notification

这里是如何使用 notificatoin 的例子 http://dev.iachieved.it/iachievedit/notifications-and-userinfo-with-swift-3-0/

您可以从 AppDelegate 发布通知并捕获到 ViewController

关于ios - 我如何与 AppDelegate 的特定 View 进行交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41971427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com