我有一个NSCollectionView
其中一个子视图是NSImageView
. 实际图像需要在通过 API 调用后从网络服务器加载(实际上是两个网络请求)。显然我需要异步加载图像。我可以将NSImageView
' 的值绑定到NSValueTransformer
将模型 id 转换为 的NSImage
,但是如何实现NSValueTransformer
?它希望立即从它的transformedValue:
方法返回,而我只能在那里触发网络请求。我不想使用同步网络阻塞线程。
问问题
382 次
1 回答
2
Rather than using a NSValueTransformer which will actually return immediately, subclass the collection view item. For each item fire the transaction in this subclasses asynchronusly. Keep a IBOutlet for the NSImage in your subclass so that when the response is received from the server jus set the Image using this IBOulet. With this approach when the item is created, the corresponding view controller comes into picture. Subclassing it gives you control over the view and how to load it.
I hope this helps.
于 2014-03-27T01:50:09.357 回答