Gaurav_soni
Gaurav_soni

Reputation: 6114

navigating to different windows when clicking button in cocoa MAC

I am new to programming on MAC. I have done programming on iOS but using storyboards so not very familiar with the xib format that was used earlier.

I want to achieve this very basic this that i am not able to figure out how.

  1. How to navigate to different windows ?

  2. How to set actions of the button ie: how to set a button click event or button rollover event?

  3. What is the meaning of linking a button from the interface builder to the first responder or to the Application or file owner.

  4. Do we have to set the class for each xib as we do in storyboard for iOS?

Thanks a lot .

Upvotes: 0

Views: 1633

Answers (2)

JeremyP
JeremyP

Reputation: 86651

How to navigate to different windows ?

On the Mac, many windows can be visible at the same time, so you don't navigate between them as such, you show them and hide them, perhaps bring them to the front etc. Exactly what you do depends on the situation.

How to set actions of the button ie: how to set a button click event or button rollover event?

You set an action for a button by control clicking the button in the xib and dragging to the controller object you want to handle it. You can then select an IBAction method to perform when the button is clicked (you must define the actions in the class's header file first). For tracking mouse-over events, look at NSViews -addTRackingRect:owner:userData:assumeInside: method. That might help.

What is the meaning of linking a button from the interface builder to the first responder or to the Application or file owner.

That just determines which object gets the action message.

Do we have to set the class for each xib as we do in storyboard for iOS?

No. Any object can load a xib and make itself the owner

[NSBundle loadNibNamed: @"whatever" owner: objectThatWillOwnIt];

Some resources

Apple's Window Programming Guide

Apple's Sheet Programming Guide (sheets are the windows that appear attached to the top of other windows e.g. things like open and save panels.

Cocoa Programming for Mac OS X, Aaron Hillegass (I learned Cocoa from the first edition of this book).

Upvotes: 2

Cristian
Cristian

Reputation: 7145

Completely agree with JeremyP if you have different XIB files and controllers in your application.

If however you have a simple application, I recommend to keep 1 window, and create Custom Views (can be found in the Inspector).

You can then add content into these Custom Views, and when you want to switch between them, in your application you can type:

[window setContentView: secondCustomView];

Then later to switch back:

[window setContentView: firstCustomView];

For good coding practice, refer to JeremyP's answer. Just thought I'd share my 2 cents :)

Upvotes: 0

Related Questions