Cocoa 如何在弹出式的NSPathControl中设置所选项目?
我有弹出式的Cocoa 如何在弹出式的NSPathControl中设置所选项目?,cocoa,Cocoa,我有弹出式的NSPathControl。当我尝试选择其他“预定义”位置时,不会发生任何更改 例如: ------------- choice... ------------- Some macBook Some desktop Some HD and etc. ------------- ------------- 选择。。。 ------------- 一些macBook 一些桌面 一些高清 等等。 ------------- 默认情况下,例如选择“Some macBook”,但当我尝试选择另
NSPathControl
。当我尝试选择其他“预定义”位置时,不会发生任何更改
例如:
-------------
choice...
-------------
Some macBook
Some desktop
Some HD
and etc.
-------------
-------------
选择。。。
-------------
一些macBook
一些桌面
一些高清
等等。
-------------
默认情况下,例如选择“Some macBook”,但当我尝试选择另一个,例如“Some HD”时,没有任何更改:弹出菜单消失,默认选择显示相同的内容。我不知道为什么会出现这种行为,这让用户非常困惑 我通常只是通过实现委托方法“禁用”它:
- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu {
// We don't want to show the useless "parent folders" menu items, as they are very confusing.
while ([[menu itemArray] count] >= 4) {
[menu removeItemAtIndex:3];
}
}
希望这有帮助 我不知道为什么会出现这种行为,这让用户非常困惑 我通常只是通过实现委托方法“禁用”它:
- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu {
// We don't want to show the useless "parent folders" menu items, as they are very confusing.
while ([[menu itemArray] count] >= 4) {
[menu removeItemAtIndex:3];
}
}
希望这有帮助 设置并连接NSPathControl h m 连接IB中的操作 *注意:我注意到,如果使用绑定对象进行连接,此操作将不会返回值。 *如果您使用绑定,则需要使用一些KVC陷阱的解决方案
-(IBAction) pathControlClicked:(id)sender {
NSPathControl* pathCntl = (NSPathControl *)sender;
NSPathComponentCell *component = [pathCntl clickedPathComponentCell]; // find the path component selected
[pathCntl setURL:[component URL]]; // set the url to the path control
_ivarStringVariable=component.URL.path;
// If you want to configure pathComponentCells here is place to do it.
}
设置并连接NSPathControl h m 连接IB中的操作 *注意:我注意到,如果使用绑定对象进行连接,此操作将不会返回值。 *如果您使用绑定,则需要使用一些KVC陷阱的解决方案
-(IBAction) pathControlClicked:(id)sender {
NSPathControl* pathCntl = (NSPathControl *)sender;
NSPathComponentCell *component = [pathCntl clickedPathComponentCell]; // find the path component selected
[pathCntl setURL:[component URL]]; // set the url to the path control
_ivarStringVariable=component.URL.path;
// If you want to configure pathComponentCells here is place to do it.
}