2

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

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

有什么建议吗?

4

1 回答 1

0

数组初始化错误

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

它应该是

_arrayTargetdevice = [[NSArray alloc] initWithArray:
                        [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
于 2013-12-20T16:29:23.400 回答