NSPopupButton,已安装卷的列表

时间:2013-12-20 15:43:24

标签: objective-c arrays nspopupbutton volumes

所有。 我是objective-c的新手,我的问题是如何连接我的PupupButton以查看我的卷列表作为连接的USB硬盘驱动器等......可选择:

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文件...但我停止了上面的错误。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

数组初始化错误

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

应该是

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