1

我正在尝试使用一组 iTunesPlaylist 对象填充 NSPopUpButton。我将 NSArrayController 绑定到 NSPopUpButton

app = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
playlists = app.sources.objectWithName("Library").userPlaylists

myArrayController.setContent playlists

所有播放列表都将出现在 NSPopUpButton 中,但它们的名称都带有

<ITunesUserPlaylist:0x4018a5000: iTunesUserPlaylist 0 of iTunes Source "Library" of Application "iTunes" (51822)>

我想要做的是将 ITunesPlaylist.name 绑定到 NSPopUpButton 的内容值,但我似乎无法让它工作。

似乎也很少有关于 Scripting Bridge API 调用返回的对象的类定义的文档(例如 ITunesPlaylist、ITunesTrack)。

有人可以给我一些指示吗?最终,我想制作一个下拉菜单,以分层形式显示用户的 iTunes 播放列表。

4

2 回答 2

1

您确定使用正确的密钥路径正确设置了绑定吗?您是否还加载了 bridgesupport 文件?我验证了 iTunesUserPlaylist 类,它应该是 KVC 兼容的。

playlists.first.valueForKey('name')

返回正确的名称。

如果您分享更多代码,我可能会调查这个问题。

此外,以下是您的播放列表中可用的一些方法:

Class: iTunesPlaylist
Properties:
duration (the total length of all songs (in seconds))
name (the name of the playlist)
parent (folder which contains this playlist (if any))
shuffle (play the songs in this playlist in random order?)
size (the total size of all songs (in bytes))
songRepeat (playback repeat mode)
specialKind (special playlist kind)
time (the length of all songs in MM:SS format)
visible (is this playlist visible in the Source list?)

Method: tracks
Returned: SBElementArray
----
Method: moveTo:(SBObject *)to
Returned: void
Move playlist(s) to a new location
----
Method: searchFor:(NSString *)for_ only:(iTunesESrA)only
Returned: iTunesTrack
search a playlist for tracks matching the search string. Identical to entering search text in the Search field in iTunes.

Class: iTunesUserPlaylist
Properties:
shared (is this playlist shared?)
smart (is this a Smart Playlist?)

Method: fileTracks
Returned: SBElementArray
----
Method: URLTracks
Returned: SBElementArray
----
Method: sharedTracks
Returned: SBElementArray
----
于 2012-02-29T06:46:50.327 回答
0

谢谢你的帮助。原来这些是我的问题:

  1. XCode 4 Interface Builder 无法识别 ArrayController 的 Class Name 字段中的类型“iTunesPlaylist”,除非我首先将“iTunes.h”导入项目,我必须生成它:

    $ sdef /Applications/iTunes.app | sdp -fh --basename iTunes

  2. 然后可以通过在 XCode IBuilder 中将 NSPopUpButton 的内容绑定中的“Modal Key Path”设置为“name”,将 Popup Button 绑定到 ArrayController 中排列对象的“name”,但默认情况下选中“Raise for Not Application Keys”所以应用程序将在启动时崩溃,因为 ArrayController 是空的。我没有选中它,一切正常

于 2012-03-02T03:42:01.713 回答