首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSPopupButton,挂载卷列表

NSPopupButton,挂载卷列表
EN

Stack Overflow用户
提问于 2013-12-20 15:43:24
回答 1查看 232关注 0票数 2

全。我是目标-c中的新手,我的问题是如何连接我的PupupButton,以查看我的卷列表作为附带的USB硬盘驱动器etc...to是可选择的:

MyController.h

代码语言:javascript
复制
@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上:

代码语言:javascript
复制
#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
}

我想要一个设备列表(可移动的和不可移动的),但是我得到了以下错误:

代码语言:javascript
复制
 - [__NSArrayI IsEqualToString:]: unrecognized selector sent to instance 0x60800001e110

我还想把磁盘标识符写到plist文件上.但我在上面的错误上停了下来。

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-20 16:29:23

数组初始化错误

代码语言:javascript
复制
_arrayTargetdevice = [[NSArray alloc] initWithObjects:
                        [[NSWorkspace sharedWorkspace] mountedRemovableMedia], nil];

它应该是

代码语言:javascript
复制
_arrayTargetdevice = [[NSArray alloc] initWithArray:
                        [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20707173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档