Swift IBAction Issue With ViewController Swap OSX - macos

I have 2 ViewControllers in an OSX swift project using storyboards. My aim is, when I click the button, the IBAction is called and the view also switches. However, despite my IBAction seeming to be good (I dragged it on and did println("hi")) "hi" is not printed, but the viewcontroller is changed. I would think it were an XCode glitch if I didn't know better, but for the life of me I can't think of what I'm doing wrong. Is anyone able to replicate this?

Can you paste the ViewController code? Is this the first time you hooked up an IBAction to that button? There might be an existing connection in the connections inspector which you haven't closed out yet?

Related

How to add an outlet between a storyboard and an NSDocument

I've done iOS for a few years, but I'm new to OS X.
I'm using the document-based template in Xcode 6. I added a textfield to the view controller in the storyboard. How do I access it from the Document?
I added:
#property(nonatomic, weak)IBOutlet NSString* aString;
to Document.h. When I drag to it, IB seems to be forcing me to use bindings. OK with me, but I'm still very weak on bindings. The dialog box asks for a number of values, most of which I can guess. But, what does "Custom Class" mean, and what should I put there?
A little help here would certainly be appreciated.
Thanks
You don't. The IBOutlet for the textfield should be in the NSViewController subclass (ViewController in the template Xcode project).
Your next question will be "How do I access the NSDocument from my view controller?"; Mac App Storyboard - Access Document in NSViewController ;-)

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.

Showing views in interface builder outside viewcontroller hierarchy in xcode5

I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!

xcode 4.5 UIBarButtonItem Action not responding, built in IB

I've set up a UIBarButtonItem in IB, created the IBAction by dragging from IB to the header file, then just put a simple breakpoint within the action in my source file....... and nothing happens.
I'm using AVCam. I can run the action from a button, but it needs to be done on a toolbar because I'm working with sharekit. I've made toolbars before, and have never had this problem before.
I connected both the toolbar and the barbutton's objects... those both work. I can hide and unhide them freely, but for some reason I just cannot get the action to call.
Anybody got any ideas?
I had a very similar problem with an UIBarButtonItem with outlets not working in Xcode 4.5 - no actions got send when I pushed the button, and the referencing outlet didn't reference to anything.
After some time and googling, I discovered that even more none of all the changes I made to my storyboard did have any effect, but hardcoding the GUI worked.
Finally, emptying Xcode project caches solved my problem - the description how to do this can be found here: How to Empty Caches and Clean All Targets Xcode 4
I had the same problem with Jeff.
For a long time, i tried lots of useless stuff.
Adding selectors programatically , bla bla bla
i also had an UITapGestureRecognizer added on viewDidLoad in order to dismiss keypad.
it was not letting gestures to reach UIView.
Not to UIBarButtonItem Click Event and many more
Not to UITableViewCell Select Event.
This solved my problem:
tap.cancelsTouchesInView=NO;
All of a sudden
UITableViewCell Select started to work
UIBarButtonItem Click event started to work.
My problem was occurring only (7.1)
Not in (8.1)

iPhone simulator not responding when using storyboards

I'm quite new to iOS Programming. I've done Objective-C for about a year, and now I want to start making apps for the iPhone. I think I'm missing out on something really simple, though. What I've done is this:
First I created a new Single View Application with TestApp as a product name. I enabled Use Storyboards, Use Automatic Reference Counting and Include Unit Tests. After creating the project, I dragged a UIButton onto the View in the storyboard file.
Note that I didn't write a single line of code. I launched my app in the iPhone Simulator and pressed the button, but it's not responding. I know I didn't assign an action to the press of the button, but the gradient of the button isn't changing, as I know it should. The User Interaction Enabled properties of both my view and my button were enabled.
Recently, I've created a few apps in Xcode that worked just fine, but I didn't use storyboards in those projects. Thus, I'm guessing there's something extra to do when using storyboards of which I'm just unaware. I'm using Xcode 4.5 and the iPhone 6.0 Simulator.
I wrote NSLog(#"View was loaded."); statement in the viewDidLoad method of my ViewController to make sure this view controller was actually loaded. (I know my button wouldn't show up if it was the wrong view controller, but I did this just to make sure.)
I also wrote a changeTitle: method in my ViewController to change the title of my button to New Title after it was pressed, just in case the button worked but its gradient just wouldn't respond to a tap. I linked this IBAction to my button, but it wasn't called.
In my ViewController, I created an IBOutlet of a UIButton which I connected to my button. In the viewDidLoad method of my ViewController, I changed the title of my button to New Title, this actually worked. The title of my button changed to this new title when launching my app in the iOS Simulator. The button itself still wasn't responding, though.
As a last try, I also wrote [button setEnabled:YES]; in my ViewController's viewDidLoad method, but this didn't help. My button still doesn't respond to any tap. What am I missing out on?
This is weird. I had an issue with my printer, so I restarted my computer. After this, this issue was suddenly solved as well (just like my printer issue). I'm not sure how this could have affected anything, but I'm glad it works again!
Ran into the same issue.
Apparently Content Reseting the Simulator worked for me
Very strange this..

Resources