Xcode: dragging from ViewController Icon - xcode

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:

Related

TouchBar don't displayed NSViewController Storyboard

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.

Linking storyboard view controller to its own viewcontroller.swift in Xcode 7.2

In the new Xcode 7.2 (iOS9), how do I add a viewcontroller.swift file and link it to a manually added view controller in the storyboard?
(This seems to be different than previous versions of Xcode where one would manually add a Cocoa Touch file after dragging a new view controller object in thestoryboard.)
Thank you.
It has always been the same for me but here are the steps that I follow.
Right click the file explorer on the left
Click Source->Next->Subclass UIViewController
Drag UIViewController into Interface Builder
Click the yellow circle to focus on the UIViewController
Click the Identity Inspector
Set the Custom Class to the name in your Swift File

storyboard navigation controller without tableview controller

Whenever I add a Navigation controller to the xcode storyboard there is a tableviewcontroller added with a "relation" connecting the two and I don't want a tableviewcontroller, I want a regular viewcontroller. How do I get that? I am trying to reproduce the following Apple PhotoPicker sample in a storyboard.
Easy:
Drag a ViewController onto the storyboard, then click "editor" and "embed in". Choose NavigationController.
Done.

asp.net vs. xcode button click

I just started learning objective c and iphone development. Coming from an asp.net and web development, I am so lost with xcode.
In asp.net, you create a button, then you can simply click on it and it takes you right to the button event. Vs. Xcode, you create a button, then you will have to create an outlet in the header file, property, IBaction. Then in the implementation (.m) file, you create the click event method for that button. After that, you have to create an outlet reference of that button touch to that event by draging...
Just out of curiosity, is there any shortcuts or easier way to do this like asp.net? Without having to create outlet, property, etc. If there are any ways to eliminate some steps would be helpful.
If you want to perform action only click button you don't need to declare UIButton IBOutlet.
Just simply drag UIButton object on your view then declare & implement IBAction method in your class. Then make connection between action and button.
There is not shortcut in xcode for this if you want to interact with interface objects in your controller class you need to declare them as property and implement using #synthesize

How do you create and attach MainMenu.xib manually in Cocoa Application?

I already started working on a few small Cocoa Application. It works just fine, but now I want to create my own MainMenu (not using the default MainMenu.xib created by XCode).
But I got a few obstacle. First, I add two XIB and its corresponding NSWindowController. The idea is the first xib will call the other xib file. But as these two xib file is a Window and with its NSWindowController, I got quite confuse on how to add the MainMenu. I create another XIB file with name MainMenu.xib, and in the startup XIB file, I do this :
- (void)windowDidLoad
{
[super windowDidLoad];
mainMenu = [[NSMenu alloc] initWithWindowNibName:#"MainMenu"];
[self setMainMenu:mainMenu];
}
but it's not working. The first startup XIB didn't display the MainMenu at all (so I can't quit the application).
As for the MainMenu.xib itself, I already connect it with the startup XIB (using NSOBject that dragged into left pane of the XIB Designer).
What is the proper way of creating main menu for multi XIB like this?
I hope I state my problem correctly, as I quite new in this Cocoa things :)
Thanks in advance!
You don't have to create another xib to change the main menu bar.
You just edit the menu bar inside the MainMenu.xib in the interface builder, that's it!

Resources