【发布时间】:2014-01-09 12:36:30
【问题描述】:
全部。 我是 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 文件...但我停止了上面的错误。
有什么建议吗?
【问题讨论】:
-
您发布的代码是可以的。我认为问题出在你删掉的那些部分 (
//more code)。 -
感谢您的回复。缺少的代码涉及其他 PopupButton(s) 及其数组和语句。没有“_targetdevicePopup”周围的所有代码,一切都很好(不幸的是)。我在 OBJ-C 方面没有足够的知识,但我会说错误是好像数组释放的数据类型不适合显示为“addItemsWithTitles”..但就像我说的我什么都没想到出
标签: objective-c arrays nspopupbutton volumes