Hey all,
I've been having some trouble working with the TopShelf. I've been using the UIKit Catalog (tvOS)[1] sample project to learn how to work with TVServices, but I've encountered a problem. I cannot seem to update the TopShelf content. The documentation says that I should post the TVTopShelfItemsDidChangeNotification message but I'm unable to see any change happening in the TopShelf.
This is the code that's called:
import UIKit
import TVServices
----
----
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
print("Before change: ")
print(DataItem.sampleItems)
DataItem.sampleItems = {
return DataItem.Group.allGroups.flatMap { group -> [DataItem] in
let itemCount: Int
switch group {
case .Scenery:
itemCount = 2
case .Iceland:
itemCount = 2
case .Lola:
itemCount = 2
case .Baby:
itemCount = 2
}
return (1...itemCount).map { DataItem(group: group, number: $0) }
}
}()
print("------------------------------------------------------------")
print("After change")
print(DataItem.sampleItems)
print("NSNotificationCenter.defaultCenter().postNotificationName(TVTopShelfItemsDidChangeNotification, object: nil) is called")
NSNotificationCenter.defaultCenter().postNotificationName(TVTopShelfItemsDidChangeNotification, object: nil)
}and this is the log (slightly edited the original samples to decrease log size):
Before change:
[UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Scenery, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Iceland, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Lola, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Baby, number: 1)]
------------------------------------------------------------
After change
[UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Scenery, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Scenery, number: 2),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Iceland, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Iceland, number: 2),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Lola, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Lola, number: 2),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Baby, number: 1),
UIKitCatalog.DataItem(group: UIKitCatalog.DataItem.Group.Baby, number: 2)]
NSNotificationCenter.defaultCenter().postNotificationName(TVTopShelfItemsDidChangeNotification, object: nil) is called
I haven't altered any project settings and the first samples do appear as expected (Iceland 1 and Lola 1), but after the code is called, nothing is changed. It still only shows Iceland 1 and Lola 1. I expected to see Iceland 1,2 and Lola 1,2. Am I missing something?