TouchBar don't displayed NSViewController Storyboard - xcode

I use Xcode 8.2.1 on macOS 10.12.3
I try to display element on TouchBar with my NSViewController but I can't do it... I have just drag&drop the TouchBar element on my NSViewController element in my Storyboard and add a label but this label is not displayed.

You have to drag the TouchBar in the Window Controller, not the View Controller. Also make sure that your Window is initial controller.
PS
An information in some ways related with this question: when, in the view, there is a text field in focus, the standard touch bar will overwrite your customized touch bar. More information here.

Related

OSX Multiple toolbars in NSTabViewController

I have a structure which is represented in the picture below (sorry but apparently in OS Sierra Xcode does not support anymore zooming in the storyboard -.- )
Window > TabController > View Controllers
Basically what I wanted to do is to have multiple toolbars, each one for a different ViewControllers. If I were on iOS I could have set a UINavigationController as target of the TabViewController and then do whatever I wanted with the related navigation bar, but here in OSX I cannot link the TabViewController to a WindowController (which handles the toolbar), hence having a window controller per view controller.
Is there any simple workaround for that?
Or the only solution is to empty-refill the toolbar with the correct buttons every time a Tab is selected?

NSWindow vs ViewController - OS X - Cocoa

I have been making iOS apps for a while now and I decided that I wanted to start working on making some of them for the Mac too.
The question I have is this: is there any need for an NSWindow, now that developing for the Mac is so similar to iOS??
So I made a simple cocoa application using Xcode and its comes with a storyboard called "Main", just like on iOS.
In that storyboard file, there is a NSWindow which then links to a NSViewController.
Can I get rid of that NSWindow? As I tried setting the NSViewController as the "Initial Controller" and the app still works fine. So whats the point of the NSWindow?
Also, what class links to the NSWindow? I was trying to blur that background of the NSWindow, but I have no way of linking code to the NSWindow.
Sorry for my stupid questions, but I am completely new to development for OS X.
Thanks for your time, Dan.
Those are many questions in one question:
Can I get rid of NSwindow? No, you need a window to show you views.
What is the point of the NSWindow? NSWindow is needed as the window in which the views are displayed and your events are going up the responder chain.
What class is linked to NSWindow? Obviously the NSWindow class, but that is not what you want to know. I think you want to know the delegate that controls NSWindow. This is NSWindowController, although for the MainMenu.xib it is NSAppDelegate.
Hope this gives you the answers you need. An example for working with views in a window is given in this question.
Please, see for further details the windows programming guide, which states:
The NSWindow class defines objects that manage and coordinate the
windows an application displays on the screen. A single NSWindow
object corresponds to at most one onscreen window. The two principal
functions of an NSWindow object are to provide an area in which NSView
objects can be placed and to accept and distribute, to the appropriate
views, events the user instigates through actions with the mouse and
keyboard.
For the question: Can I get rid of NSwindow? I have further comments. In most cases, You need a NSWindow to show view on screen; but in special case you don't, for example, a popup view when you click a NSStatusItem.
So my answer is whenever you need to respond window event such as min/max, you need NSWindow as the view container.

XCode, Storyboard, View Controller items are not being displayed

When opening up a project today, there is some weird behavior in XCode. Things have disappeared in the storyboard view like the NavigationBar in viewController, the buttons associated with it, etc. I can see in the Scene list that they still exist. Is there any way to have these show up again?
You probably need to add a navigation controller to your storyboard and make your view controller the root. You cannot simply set the top bar in simulated metrics in storyboard to navigation bar.

Xcode: dragging from ViewController Icon

In Xcode,
what does it mean to drag from the orange ViewController icon to lets say a Label.
how is this different from dragging a line from the Label to the interface to setup an outlet?
If you don't use the assistent editor (interface builder and header file) then one way dragging is making an outlet, and the other way is to make an action (for example to make a UIButton IBAction method).
When you use the assistent editor you can just drag from the UI object to the header file and choose to make an outlet or an action:

Cocoa custom view for NSMenuItem

I am developing a small app that display the active mounts in a menu in the NSStatusBar. So far it looks like this:
I want to add an eject button to the right of each menu item (like the left bar in the Finder). I know that I have to create a custom view and set it with the setView: method. The problem is that I am very new to Cocoa and right now I don't know how to dive into the custom view topic. Actually, I programmed a lot but never worked with interfaces so far :). Does anyone of you have a good tutorial for adding a custom view to a NSMenuItem?
I think this app will be very handy because you can hide the mounted icons from your desktop. The problem is that you always have to go back to the finder to unmount a volume...
Thanks for any help or tips you have!
It doesn't have to be a custom view. It can just be a standard NSView that acts as a container for standard controls.
The tricky part for a newbie is making the view reusable. You'll want your own NSViewController subclass with a corresponding view nib/xib (set up with your name label and eject button). For each menu item, you'll instantiate a new NSViewController with the XIB ( -initWithNibName:bundle: ) and set its represented object to your mount point. Your view controller subclass will have all it needs to respond to the eject button click, set the label to its represented object's path, etc.

Resources