문제

I have a list of applications and I'd like to make an NSPopupButton that shows a menu of application names with their icon to the left of each item.

I've been able to bind the NSPopupButton to my array of items, but there isn't a binding entry for an image. I thought I could put a cell in there and bind the cell as an image and as text, but I can't find an appropriate cell in IB.

Is there a clean and simple way to do this using bindings? Do I have to write a custom cell?

도움이 되었습니까?

해결책

There is no way to bind the images as well as the titles of the menu items using a stock NSPopUpButton. You will have to subclass it and write an IBPlugin to expose the subclass. And, of course, you should handle the cell as well.

I've found mixing Bindings with NSPopUpButton to be a bag of hurt for a variety of reasons, including the impossibility of separators and of out-of-model menu items such as “Default” or “All”. Consider using a different control, such as a source list, or populating and re-populating the pop-up menu manually.

다른 팁

NSMenuItem has Image binding (in "Parameters" section waaaaaayyyyy down). So I think that you should bind that value to a path in your array of running applications. You can get an icon for your app using shared NSWorkspace object.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top