Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > [hopefully] 3 simple questions (obj-c)

[hopefully] 3 simple questions (obj-c)
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2001
Location: Murray, Utah, USA
Status: Offline
Reply With Quote
May 22, 2001, 12:59 PM
 
Hopefully the 3 problems I am having w/ Obj-C and PB/IB are simple (as I am
new to Obj-C) and can be quickly worked out

1. I can make a "preferences" window, fill it with controls and be fine.
However, the only way I can think of to get those values is to make a NSView that is "all-encompassing" of my program, which has outlets to those values. It works, but is very sloppy. Is there another way?

2. Kind of related to #1 -- How can make an object that I "have access to"
in PB? I know that is worded poorly. Example (from #1): I make a MyPrefs
object in IB that is a subclass of NSObject, then instantiate it w/ all the
outlets to controls in the Preferences window. But how do I access those
values in my code? MyPrefs is a class type, not an instance variable... I
hope my problem is understood =)

3. Lastly, how on earth do I make a modal dialog? I assume this has to be done with a "sheet", but I don't have any idea how to begin doing this...

Thanks,
Jeff

     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 22, 2001, 01:18 PM
 
To create a set of preferences to access globally, the best way is using the NSUserDefaults object. You can basically use it like an NSMutableDictionary to set and retrieve preferences for just about anything, it handles all the nitty-gritty details of saving the preferences, etc. Check out this tutorial at CocoaDevCentral.
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
May 23, 2001, 04:33 PM
 
I'm not exactly sure what you're asking, but here goes :-)

You can have as many nibs as you like in a program. When the NSBundle method -loadNibNamed:owner: is used, the owner exists before the .nib is loaded, and is represented in the .nib as the "File's Owner". Thus, typically you create a controller class of some sort that has outlets to what you need (plus some action methods maybe), and use that class to load the .nib, passing self as the owner. You don't need an NSView subclass particularly, in fact you almost always won't want an NSView subclass for this kind of thing.

If you make your controller a subclass of NSWindowController, then it will deal with loading the .nib for you, which is kind of nice. You can override the -windowDidLoad method to do any initialization you need after the nib is loaded but before it becomes visible.

As noted, use NSUserDefaults to actually store the preference settings. Code that needs to use pref values can then just ask NSUserDefaults for them.

If you want an example of a pref panel controller that's a subclass of NSWindowController, you can see my ManOpen application at http://www.clindberg.org . It's a little light on comments, but it does work.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:12 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2