【问题标题】:Cannot subscript a value of type [MPMediaItem] #2无法下标 [MPMediaItem] #2 类型的值
【发布时间】:2016-03-03 19:27:03
【问题描述】:

我知道在 cannot subscript a value of type [MPMediaItem] 以完全相同的方式提出了这个问题,但我没有得到他的解决方案。

cell.textLabel!.text = allSongs![indexPath.row]

这是我正在尝试的。

allSongs 是这样声明的 var allSongs = [MPMediaItem]?()

【问题讨论】:

  • 您遇到什么错误?确保行小于数组的计数。
  • 我的错误和标题“Cannot subscript a value of type [MPMediaItem]”一模一样,行是allSongs.count
  • 您将MPMediaItem 分配给需要String 的属性
  • 如何将 MPMediaItem 转换为字符串? @丹
  • 然后做cell.textLabel!.text = allSongs![indexPath.row].title

标签: ios swift uitableview mpmediaitem


【解决方案1】:

你可能想做一些链接这个:

 cell.textLabel!.text = allSongs![indexPath.row].valueForProperty(MPMediaItemPropertyTitle) as? String

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多