How to use NSToolBar in Xcode 6 and Storyboard?

后端 未结 6 2066
予麋鹿
予麋鹿 2020-12-05 06:05

I\'ve been trying to build on a Cocoa app that uses Swift and Storyboard in Xcode 6, but how can I use NSToolbar there?

In Xcode 5 and xib, you can add

6条回答
  •  青春惊慌失措
    2020-12-05 06:08

    This helped me for the IBOutlet solution you are looking for: https://stackoverflow.com/a/27555237/3398062

    Update (explanation)

    I discovered this thread because I was trying to create a Circular Progress Indicator inside the toolbar and I didn't know how to animate it from the ViewController since the IBOutlet was declared inside a custom WindowController.

    Finally, I found the post that I have added above which describes how to access to IBOutlets from other classes.

    In essence what I have done is the following:

    • Create a custom NSWindowController subclass (CustomWindowController) for the Window Controller so I can add the IBOutlet for the ProgressIndicator:

    Code Example:

    @interface CustomWindowController : NSWindowController
    
    @property (weak) IBOutlet NSProgressIndicator *progressIndicator;
    
    @end
    
    • Then in the ViewController class, in the method I want to use to update the state of the Progress Indicator, I create and object of the custom Window Controller.

    Code Example:

    CustomWindowController *customWindowController = self.view.window.windowController;`
    
    • Finally, to change the state of the Progress Indicator there is only to call the method from the created custom object.

    Code Example:

    [customWindowController.progressIndicator startAnimation:sender];
    

    or

    [customWindowController.progressIndicator stopAnimation:sender];
    

提交回复
热议问题