NSArrayController实例

  NSController是一个抽象类。NSObjectController是NSController的子类,用于显示对象的信息和内容。NSArrayController是数据对象array的controller。

1.创建一个基于文档的工程application,Document类中包含属性NSMutableArray*employees.创建模型类Person,含属性NSString * personName,和float expectedRaise;

2.在Document.xib文件中删除文本框,放一个Cell Based 的tableView(两列:Name,Raise),两按钮Add Employee 和Remove

3. 在Document.xib中放置一个NSArrayController(在Cocoa->Object & Controllers中),选中NSArrayController,在Attributes Inspector,在Object controller下设置类名Person,添加键personName和expectedRaise;切换到Bindings Inspector,在列表中找到Content Array binding,展开,单击Bind to ,在弹出的菜单中选中File's Owner,保存Controller Key 为空白,在Model Key Path中输入employees.此时就将array控制器的Content Array绑定到File's Owner的employees队列上了。

4.单价表格的Name列,找到Value Binding,选中Bind to ,在弹出的菜单中选择Array Controller,设置Controller Key为arrangedObjects,Model Key Path 为personName.类似绑定Raise到Array Controller 的expectedRaise

5.给两按钮Add Employee 和Remove设置target,使用控制拖拽,从Add Employee按钮拖拽到array控制器来设置按钮的target,设置action为add:,同样放发设置Remove的action为remove:,为Remove在Binding Inspector中绑定按钮的enable为array Controller 的canRemove属性

 

转载于:https://www.cnblogs.com/PJXWang/p/5326814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值