2012-02-27 21 views
1

我想用ITunesPlaylist對象數組填充NSPopUpButton。我得到了NSArrayController的結合NSPopUpButton如何在MacRuby中將NSPopUpButton與ITunesPlaylist對象綁定?

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播放列表。

回答

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 
---- 
+0

感謝您的幫助。原來,這些是我的問題: – goofrider 2012-03-02 03:27:05

0

感謝您的幫助。原來,這是我的問題:

  1. 的XCode除非我輸入「iTunes.h」到項目前4 Interface Builder中不承認在ArrayController的類名稱字段類型「iTunesPlaylist」,我不得不生成它:

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

  2. 然後,通過在XCode IBuilder的NSPopUpButton的內容綁定中將「Modal Key Path」設置爲「name」,Popup Button可以綁定到ArrayController中的arrangedObjects的「名稱」但默認情況下選中「不提供應用程序密鑰」,因此應用程序將在啓動時崩潰,因爲ArrayController爲空。我沒有選中它,一切正常

+1

有關頭文件和文檔的更多信息,可以閱讀我的舊博客文章:http://merbist.com/2010/01/17/controlling-itunes-with- macruby/ – 2012-03-03 04:58:54

+0

其實你的文章是我遇到的解釋iTunes.h要求的地方之一。偉大的職位! – goofrider 2012-03-10 12:14:40