NSToolbar自定义不可用

huangapple go评论54阅读模式
英文:

NSToolbar customization not available

问题

According to the documentation, this property has been available since macOS 10.4.

I'm on High Sierra 10.13 and getting an error:

../src/osx/cocoa/toolbar.mm:465:15: warning: instance method '-allowsUserCustomization:' not found (return type defaults to 'id')
      [-Wobjc-method-access]
        [self allowsUserCustomization:YES];
              ^~~~~~~~~~~~~~~~~~~~~~~
../src/osx/cocoa/toolbar.mm:339:12: note: receiver is an instance of the class declared here
@interface wxNSToolbar : NSToolbar
           ^
../src/osx/cocoa/toolbar.mm:466:15: warning: instance method '-autosaveConfiguration:' not found (return type defaults to 'id')
      [-Wobjc-method-access]
        [self autosaveConfiguration:YES];
              ^~~~~~~~~~~~~~~~~~~~~
../src/osx/cocoa/toolbar.mm:339:12: note: receiver is an instance of the class declared here
@interface wxNSToolbar : NSToolbar
           ^

Could someone please explain what is going on?

TIA!!

[EDIT]

I made the following implementation:

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
    auto array = [NSArray arrayWithObjects:&m_default[0] count:m_default.size()];;
    return [NSArray arrayWithObjects:&m_default[0] count:m_default.size()];;
}

- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
    auto array = [NSArray arrayWithObjects:&m_allowed[0] count:m_allowed.size()];;
    return [NSArray arrayWithObjects:&m_allowed[0] count:m_allowed.size()];;
}

However, after executing the line auto array = ..., the program crashes.

The variables m_allowed and m_default are of the type std::vector.

The vectors do have elements in them. Running under lldb, I can see their content.

What am I doing wrong?

英文:

ALL,

According to the documentation the property is available since macOS 10.4.

I'm on High Sierra 10.13 and getting an error:

../src/osx/cocoa/toolbar.mm:465:15: warning: instance method '-allowsUserCustomization:' not found (return type defaults to 'id')
      [-Wobjc-method-access]
        [self allowsUserCustomization:YES];
              ^~~~~~~~~~~~~~~~~~~~~~~
../src/osx/cocoa/toolbar.mm:339:12: note: receiver is instance of class declared here
@interface wxNSToolbar : NSToolbar
           ^
../src/osx/cocoa/toolbar.mm:466:15: warning: instance method '-autosaveConfiguration:' not found (return type defaults to 'id')
      [-Wobjc-method-access]
        [self autosaveConfiguration:YES];
              ^~~~~~~~~~~~~~~~~~~~~
../src/osx/cocoa/toolbar.mm:339:12: note: receiver is instance of class declared here
@interface wxNSToolbar : NSToolbar
           ^

Could someone please explain what is going on?

TIA!!

[EDIT]

I made a following implementation:

- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
    auto array = [NSArray arrayWithObjects:&m_default[0] count:m_default.size()];;
    return [NSArray arrayWithObjects:&m_default[0] count:m_default.size()];;
}

- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
    auto array = [NSArray arrayWithObjects:&m_allowed[0] count:m_allowed.size()];;
    return [NSArray arrayWithObjects:&m_allowed[0] count:m_allowed.size()];;
}

However, after executing the line auto array = ..., program crashes.

The variables m_allowed and m_default are of the type std::vector.

The vectors do have elements in them. Running under lldb I can see their content.

What am I doing wrong?

答案1

得分: 0

设置一个属性在Objective-C中:

self.allowsUserCustomization = YES;

使用setter方法:

[self setAllowsUserCustomization:YES];
英文:

Setting a property in Objective-C:

self.allowsUserCustomization = YES;

Using the setter method:

[self setAllowsUserCustomization:YES];

huangapple
  • 本文由 发表于 2023年5月25日 21:56:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333097.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定