【发布时间】:2019-09-24 20:35:08
【问题描述】:
我有 func 返回随机生成的加密货币的结构数组,然后将其传递给 tableView。 我遇到了这个错误无法将类型“NSNotification.Name”的值转换为预期的参数类型“通知”我是否朝着正确的方向前进?
【问题讨论】:
标签: swift
我有 func 返回随机生成的加密货币的结构数组,然后将其传递给 tableView。 我遇到了这个错误无法将类型“NSNotification.Name”的值转换为预期的参数类型“通知”我是否朝着正确的方向前进?
【问题讨论】:
标签: swift
Notification.Name 只是一个字符串。你需要做的是使用这个Name 构造一个通知。在您的postNotification(notification:) 方法中,您传递的是String,而不是Notification。
尝试将此代码:postNotification(notification: Notificator.dataUpdateNotification) 替换为:postNotification(notification: Notification(name: Notificator.dataUpdateNotification))。
您需要将Notification 传递给此方法,但您传递的是Notification.Name,它是String,而不是Notification。
【讨论】:
CryptoTableViewController中,你有没有声明quotes的cellForRowAtIndexPath:和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 来显式解开出列单元格,然后将括号中的所有内容从括号中取出。可能发生的情况是您的单元格由于某种原因没有出队,例如标识符不正确。如果是这种情况,该应用程序将在该行出现致命错误,我们将能够确定这是否是原因。