objective-c - 使用多个 nsarraycontroller 更改选定对象

标签 objective-c macos cocoa binding nsarraycontroller

我正在尝试实现如 developer.apple.com 所示的示例 一切正常,但 selectedWeapon 没有改变。

Q1:我不知道我忘记了什么,所以选择可以正常工作 问题 2:根据 Apple 的说法,“该示例不需要实际代码来设置用户界面”。我正在从代码填充对象。有什么方法可以将对象添加到 XIB 中的 arrayController 中吗?

@implementation Combatant

- (instancetype)initWithName:(NSString *)aName
{
  self = [super init];
  if (self) {
    _weapons = @[@"Dagger", @"Sword", @"Pike"];
    _name = aName;
    _selectedWeapon = [_weapons firstObject];
  }
  return self;
}

@end

@interface Combatant : NSObject


@property (nonatomic, strong) NSString *name;
@property id selectedWeapon;
@property NSArray *weapons;

- (instancetype)initWithName:(NSString *)aName;

@end

存储库:https://github.com/xhruso00/moderatelyComplexBindings

enter image description here

enter image description here

enter image description here

最佳答案

Q1: NSPopupButton 的选择索引没有链接到 arrayController。没有它,arrayController 就不知道选择了哪个选项。 Q2:不可能。 Apple 谈论粘合代码。

enter image description here

关于objective-c - 使用多个 nsarraycontroller 更改选定对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25628807/

相关文章:

ios - 如何在ios中多次调用同一个服务并存储数据

ios - 基于 CGFloat 的数学函数?

ios - 如何在特定索引处将数组插入现有NSMutableArray中

c++ - Curl 与 Catalina C++ 失败并获得 "Undefined symbols for architecture x86_64"

macos - "llvm-g++: command not found"构建比特币时

macos - 10.11 NSCollectionView : "could not load the nibName: NSCollectionViewItem in bundle NSBundle"

macos - 如何知道 NSTableView 何时完成(重新)加载其内容?

iphone - 自定义单元格崩溃

objective-c - NSString 中的 stringWithString 和 initWithString 中的对象所有权

cocoa - 从另一个 Controller 调用函数,为什么不起作用?