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 ... но я остановился на ошибке выше.
Любые советы?
код вы вывесили в порядке. Я думаю, что проблема кроется в тех частях, которые вы вырезали ('// more code'). – akashivskyy
Спасибо за ответ. Пропущенный код относится к другим PopupButton (s), с их массивами и их утверждениями. Все в порядке без всего кода вокруг «_targetdevicePopup» (к сожалению). У меня нет достаточных знаний в OBJ-C, но я бы сказал, что ошибка такова, что тип данных, выпущенных массивом, не подходит для отображения как «addItemsWithTitles» .. Но, как я уже сказал, у меня ничего нет разобрался – Mike97