【问题标题】:App crash when I'm trying to updating an app when returning from background in iOS using swift 3当我使用swift 3从iOS后台返回时尝试更新应用程序时应用程序崩溃
【发布时间】:2017-03-09 05:20:54
【问题描述】:

我在viewdidload()使用这个代码

NotificationCenter.default.addObserver(self, selector: Selector(("appWillEnterForeground:")), name: NSNotification.Name.UIApplicationDidBecomeActive, object: UIApplication.shared)

调用这个函数

func appWillEnterForeground(notification: NSNotification!) {
    // update label text here
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(true)
    NotificationCenter.default.removeObserver(self)
}

但该应用程序在返回前台时崩溃

unrecognized selector sent to instance 0x160db800
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ appWillEnterForeground:]: unrecognized selector sent to instance 0x160db800'

【问题讨论】:

    标签: swift3 ios10


    【解决方案1】:

    appWillEnterForeground: 告诉通知中心查找具有该名称的方法,但该方法需要一个参数。您的方法实现不带参数,因此不被视为正确匹配。

    试试Selector(("appWillEnterForeground")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      相关资源
      最近更新 更多