2013-12-20 51 views
2

全部。 我在Objective-C新的,和我的問題關於如何連接我的PupupButton看到我的卷的列表作爲連接的USB硬盤驅動器等..可以進行選擇:NSPopupButton,掛載卷列表

MyController.h

@interface MyController : NSWindowController <NSWindowDelegate, NSTableViewDataSource, NSTabViewDelegate, NSApplicationDelegate, NSOpenSavePanelDelegate> 
{ 
@private  
#if !__has_feature(objc_arc) 
    NSPopUpButton *_targetdevicePopup; 
// etc 
#endif 

    NSArray*_arrayTargetdevice; 
} 

#if !__has_feature(objc_arc) 
@property (nonatomic, retain) IBOutlet NSPopUpButton *targetdevicePopup; 
//etc 
#else 
@property (assign) IBOutlet NSPopUpButton *targetdevicePopup; 
/etc 
#endif 
// -- // 

這在我的.m:

#import "MyController.h" 
#import "AppDelegate.h" 
#import <IOKit/IOKitLib.h> 
#import <DiskArbitration/DiskArbitration.h> 
@interface MyController() 

@end 

@implementation MyController 
#if !__has_feature(objc_arc) 
@synthesize targetdevicePopup  = _targetdevicePopup; 
//etc 
#endif 

#if !__has_feature(objc_arc) 
- (void)dealloc 
{ 
    [_targetdevicePopup release]; 
//etc 
} 
#endif 


- (id)init 
{ 
    self = [super initWithWindowNibName:@"MyController"]; 
    if (self) { 

    } 
    return self; 

} 

- (void)windowDidLoad 
{ 
    [super windowDidLoad]; 

//more code  

    _arrayTargetdevice = [[NSArray alloc] initWithObjects: 
         [[NSWorkspace sharedWorkspace] mountedRemovableMedia], nil]; 

    [_targetdevicePopup addItemsWithTitles:_arrayTargetdevice]; 
    for (int i = 0; i <= [_arrayTargetdevice count]; i++) { 
     [[_targetdevicePopup itemAtIndex:i] setTag:i]; 
    } 

    [[[_targetdevicePopup menu] 
     itemWithTitle:@"Not Selected"] setTitle:NSLocalizedString(@"Not Selected", nil)]; 

//more code 
} 

我想我的設備列表(可移動的和沒有),但我得到這個錯誤:

- [__NSArrayI IsEqualToString:]: unrecognized selector sent to instance 0x60800001e110 

我也想寫一個plist文件的磁盤標識符......但是我停止了上面的錯誤。

有什麼建議嗎?

+0

您發佈的代碼就可以了。我認爲問題出在你切出的部分('//更多的代碼')。 – akashivskyy

+0

感謝您的回覆。 缺少的代碼涉及其他PopupButton(s)及其數組及其語句。沒有圍繞「_targetdevicePopup」的所有代碼(不幸),一切都可以。 我沒有足夠的OBJ-C知識,但我會說錯誤就好像數組發佈的數據類型不適合顯示爲「addItemsWithTitles」..但就像我說的,我什麼也沒有想通了 – Mike97

回答

0

數組的初始化錯誤

_arrayTargetdevice = [[NSArray alloc] initWithObjects: 
         [[NSWorkspace sharedWorkspace] mountedRemovableMedia], nil]; 

應該

_arrayTargetdevice = [[NSArray alloc] initWithArray: 
         [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];