2012-02-19 9 views
0

iTunesですべてのプレイリストのリストを取得し、ユーザーが選択できるポップアップボタンに配置しようとしています。NSMutable辞書のキーをポップアップボタンに表示する

私は、iTunesとのインターフェイスをとるカスタムクラスを作成し、プレイリストを取得してNSMutableDictionaryに埋め込みました。

次に、AppDelegateのiTunesコントローラクラスを「iTunesInterface」としてインスタンス化しました。

私は、ボタンをポップアップ選択し、辞書コントローラの配置されたにコンテンツとコンテンツの値をバインド辞書コントローラを作成し、モデルキーパスiTunesInterface.userPlaylists

でAppDelegateにそれをバインド私の.xibファイルで

オブジェクト...

すべてがコンパイルされますが、ポップアップボタンに何も表示されません。それは完全に空です。私が間違っていることを確信していない。ここでは、コードです:

iController.h:

#import <Foundation/Foundation.h> 
#import "iTunes.h" 

@interface TuneController : NSObject 
{ 
    iTunesApplication *iTunes; 
    NSMutableDictionary *userPlaylists; 
} 

@property (retain, nonatomic) iTunesApplication *iTunes; 
@property (copy, nonatomic) NSMutableDictionary *userPlaylists; 

- (NSMutableDictionary *) playlists; 


@end 

iController.m

#import "iController.h" 

@implementation TuneController 

@synthesize iTunes; 
@synthesize userPlaylists; 


- (id) init { 
    self = [super init]; 
    if (self) 
    { 
     // Create iTunes Object 
     iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; 
     userPlaylists = [self playlists]; 
    } 
    return self; 
} 

- (NSMutableDictionary *) playlists { 

    NSArray *sources = [iTunes sources]; 
    iTunesSource *librarySource = nil; 

    for (iTunesSource *source in sources) { 
     if ([source kind] == iTunesESrcLibrary) { 
      librarySource = source; 
      break; 
     } 
    } 

    SBElementArray *playlists = [librarySource userPlaylists]; 
    NSMutableDictionary *playlistNames = nil; 
    int i = 0; 

    for (SBElementArray *list in playlists) { 
     [playlistNames setObject:[playlists objectAtIndex:i] forKey:[[playlists objectAtIndex:i] name]]; 
     NSLog(@"Playlist Name: %@", [[playlists objectAtIndex:i] name]); // This is how I know I'm getting good values for the dictionary... 
     i++; 
    } 

    return playlistNames; 

} 

@end 

AppDelegate.h

#import <Cocoa/Cocoa.h> 
#import "iController.h" 

@interface SCAppDelegate : NSObject <NSApplicationDelegate> 
{ 
    TuneController *iTunesInterface; 
} 

@property (copy, nonatomic) TuneController *iTunesInterface; 
@end 
の関連セクション210

AppDelegate.mの関連セクション

#import "SCAppDelegate.h" 
#import "iController.h" 


@implementation SCAppDelegate 
... 
@synthesize iTunesInterface; 
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 
    iTunesInterface = [[TuneController alloc] init]; 
} 

私はこれに対して私の頭を叩いていて、私の値は、ポップアップボタンに表示されない理由を把握することはできません。助言がありますか?あなたの助けを前もってありがとう!

答えて

1

TuneController::playlistsは、playlistNamesが決して初期化されないので、現時点では常にnilを返します。

+0

まだサイコロはありません。: - \ –

+0

ok、コード内の位置を少し明確に指し示すように答えを編集しました – umjasnik

+0

これは最終的に!本当にありがとう!これは意味をなさない... ObjCはNil参照をNilとして返すだけなので、コンパイラはエラーになりません。 –

関連する問題