【问题标题】:Can I call notification function in timer?我可以在计时器中调用通知功能吗?
【发布时间】:2019-09-24 20:35:08
【问题描述】:

我有 func 返回随机生成的加密货币的结构数组,然后将其传递给 tableView。 我遇到了这个错误无法将类型“NSNotification.Name”的值转换为预期的参数类型“通知”我是否朝着正确的方向前进?

【问题讨论】:

    标签: swift


    【解决方案1】:

    Notification.Name 只是一个字符串。你需要做的是使用这个Name 构造一个通知。在您的postNotification(notification:) 方法中,您传递的是String,而不是Notification

    尝试将此代码:postNotification(notification: Notificator.dataUpdateNotification) 替换为:postNotification(notification: Notification(name: Notificator.dataUpdateNotification))

    您需要将Notification 传递给此方法,但您传递的是Notification.Name,它是String,而不是Notification

    【讨论】:

    • 谢谢!现在这两者之间的区别很明显了。我修复了错误,但 tableView 没有更新。您认为我应该如何更改代码?可能是逻辑不对。
    • CryptoTableViewController中,你有没有声明quotescellForRowAtIndexPath:numberOfRowsInSection:方法作为tableView的数据源?
    • 尝试通过将if let cell = tableView.dequeueReusableCell(withIdentifier: “QuoteCell”, for indexPath: indexPath) as? QuoteCell 更改为let cell = tableView.dequeueReusableCell(withIdentifier: “QuoteCell”, for indexPath: indexPath) as! QuoteCell 来显式解开出列单元格,然后将括号中的所有内容从括号中取出。可能发生的情况是您的单元格由于某种原因没有出队,例如标识符不正确。如果是这种情况,该应用程序将在该行出现致命错误,我们将能够确定这是否是原因。
    • 不幸的是,没有任何改变 :( 感谢您的帮助!看来问题出在其他地方。
    猜你喜欢
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2020-09-24
    • 2021-03-01
    • 1970-01-01
    • 2017-12-27
    相关资源
    最近更新 更多