【问题标题】:How do I bind NSPopUpButton with ITunesPlaylist objects in MacRuby?如何在 MacRuby 中将 NSPopUpButton 与 iTunesPlaylist 对象绑定?
【发布时间】:2012-02-27 19:33:45
【问题描述】:

我正在尝试使用一组 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 播放列表。

【问题讨论】:

    标签: macos cocoa itunes macruby scripting-bridge


    【解决方案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
    ----
    

    【讨论】:

    • 感谢您的帮助。原来这些是我的问题:
    【解决方案2】:

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

    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”,但“Raise for Not Application”将弹出按钮绑定到 ArrayController 中的排列对象的“名称” Keys" 默认选中,因此应用程序将在启动时崩溃,因为 ArrayController 为空。我取消选中它,一切正常

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    相关资源
    最近更新 更多