【发布时间】:2011-04-17 18:09:28
【问题描述】:
我有两个笔尖:
- Store.nib
- Product.nib
Product.nib 的文件所有者是NSViewController 的子类,它有一个属性product,各种控件都绑定到该属性:
@property(nonatomic, retain) SRProduct *product;
Store.nib 有一个NSArrayController 对象,该对象已绑定到SRApplicationController 的属性,即此属性:
@property(nonatomic, retain) NSArray *products;
SRApplicationController 有一个到该NSArrayController 对象的出口。
在 -[SRApplicationController init] 方法中,我使用 Product.nib nib 初始化一个 SRProductController 对象。在-[SRApplicationController awakeFromNib] 中,我将产品控制器的视图添加到Store.nib 中的视图中,并将SRApplicationController 对象的productsArrayController 属性(插座)绑定到产品控制器的product:
- (id)init {
if (self = [super init]) {
self.productController = [[SRProductController alloc] initWithNibName:@"Product" bundle:nil];
}
return self;
}
- (void)awakeFromNib {
[self.productView removeAllSubviews]; // this method is from a category
[self.productView addSubview:self.productController.view];
[self.productController.view setFrame:self.productView.bounds];
[self.productsArrayController bind:@"selectedObjects" toObject:self.productController withKeyPath:@"product" options:nil];
}
当我运行该应用程序时,我没有收到任何错误,没有警告,控制台仍然是空的,Store.nib 中包含所有产品的表格视图显示了所有产品,我可以选择它们。问题是 Product.nib 中的所有字段都是空的,但它们都绑定到文件所有者的 product 属性。谁能帮我解决这个问题?提前致谢。 :)
【问题讨论】:
标签: objective-c cocoa model-view-controller cocoa-bindings