全。我是目标-c中的新手,我的问题是如何连接我的PupupButton,以查看我的卷列表作为附带的USB硬盘驱动器etc...to是可选择的:
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文件上.但我在上面的错误上停了下来。
有什么建议吗?
发布于 2013-12-20 16:29:23
数组初始化错误
_arrayTargetdevice = [[NSArray alloc] initWithObjects:
[[NSWorkspace sharedWorkspace] mountedRemovableMedia], nil];它应该是
_arrayTargetdevice = [[NSArray alloc] initWithArray:
[[NSWorkspace sharedWorkspace] mountedRemovableMedia]];https://stackoverflow.com/questions/20707173
复制相似问题