swift - 连接到互联网时刷新应用程序

标签 swift uiviewcontroller uirefreshcontrol

目前,如果我在没有互联网连接的情况下启动我的应用程序,屏幕只会启动白色。

然后,当您连接到互联网并再次启动该应用程序时,它仍将保持白色(除非您完全关闭该应用程序并通过互联网连接启动该应用程序。)

所以我希望能够制作某种保留页面,显示没有互联网连接,然后一旦应用程序再次启动并连接到它,它将自动刷新或重定向页面以显示正确的内容。

我想知道是否有刷新 View Controller 的方法?我只能在 TableView Controller 中看到它吗?

最佳答案

要刷新您自己的 View Controller ,只需编写您自己的更新例程。例如

func upateUI(data: [String: AnyObject]) {
   nameLabel?.text = data["name"] as? String
   mySwitch.on = data["active"] as! Int > 0
   // etc.
}

一种常见的方法是使用NSNotification 来提醒任何可见的 View 。只需在通知变得可见时通过 NSNotificationCenter 注册通知,并在它离开屏幕时取消注册。

关于swift - 连接到互联网时刷新应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31609107/

相关文章:

iOS 10.0 UIRefreshControl 不显示指示器

arrays - 将字符串复制到模型(Swift 3)

ios - UIRefreshControl 在 Collection View 中不起作用

ios - 如何调整 View 层次结构中的 UIRefreshControl 位置?

iPad 模态表单无论如何都会占据整个屏幕

ios - 导航 Controller 始终为零

ios - 将日期选择器日期传回 View Controller 以在标签中显示日期

swift - 自动布局看起来因屏幕尺寸而异

swift - 避免重复属性方法

swift - ascii to string swift 3 问题