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 > NSMatrix and NSDefaults

NSMatrix and NSDefaults
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 30, 2002, 07:27 PM
 
Does anyone have any code which illustrates getting and setting defaults for an NSMatrix? I am able to set preferences for all the IB buttons switches and sliders but cant get a matrix of buttons to work.
3R1C
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
May 30, 2002, 10:49 PM
 
As in, you're writing a preferences pane or some such, and you know how to get the value of a checkbox or slider and save/restore it to NSUserDefaults but aren't sure how to do it with a matrix (like a radio button group)?

It's pretty easy. Connect the matrix's target/action, and in that method, find out which radio button is selected with [sender selectedCell]. Once you have that, you can use any of several methods to figure out which cell it is... generally, the cell's tag is a good way to go, since IB makes sure all cells have a unique tag.

For cases where you have only two options in a radio matrix, you can use a boolean preference and make sure the cell tags are 0 and 1. For example:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (IBAction)twoWayMatrixClickedid)sender;
{
[defaults setBool:[[sender selectedCell] tag] forKey:@&quot;OpenBookmarksInNewWindow&quo t;]
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">If you have several options, you can store them in any of several different ways. Here's one example:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (IBAction)threeWayMatrixClickedid)sender;
{
switch ([[sender selectedCell] tag]) {
case 0:
[defaults setObject:@&quot;ChangeAutomatically&quot; forKey:@&quot;BookmarkRedirectBehavior&quo t;];
break;
case 1:
[defaults setObject:@&quot;AskToChange&quot; forKey:@&quot;BookmarkRedirectBehavior&quo t;];
break;
case 2:
default:
[defaults setObject:@&quot;DontChange&quot; forKey:@&quot;BookmarkRedirectBehavior&quo t;];
}
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Disclaimer: I wrote these methods right here in the forum, so they might have minor syntax errors if you try to use them verbatim. They're based on the radio button groups in OmniWeb's Bookmark preferences pane, in case you're curious as to what UI I had in mind when I was writing them.
Rick Roe
icons.cx | weblog
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 30, 2002, 11:44 PM
 
Ok. I think I have my brain wrapped around what you gave me. I f you could tell me one more thing, I will KNOW whether I have my brain around it.

How do set the proper radio button in the matrix to the users previous preference on opening of the preferences?

HEY! I think I really do have it! (breathes steamy breath on fingernails and polishes them on lapel)

[tableUpdateTypePref selectCellWithTag:[[NSUserDefaults standardUserDefaults] boolForKey:@"tableUpdateTypePref"]];

Man, thanx Rickster. I tell you. I think apple really has something there with making developers out of users. I've been using computers for 20 years and it took OS X via cocoa to get me to program with any success.

I LOVE COCOA!

<small>[ 05-31-2002, 01:57 AM: Message edited by: 3R1C ]</small>
3R1C
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
May 31, 2002, 01:58 AM
 
Yeah, you've got it.

An additional tip, and shameless plug: the OAPreferences subsystem in the OmniAppKit framework makes preference panels really easy. And our <a href="http://www.omnigroup.com/developer/sourcecode" target="_blank">open source</a> site now includes an example application showing you how to use it. But even if you don't, there are some tricks you can use to make writing preference panes easier. One of the things we do is collect all the UI actions into one method, -setValueForSender:, which inspects its argument to find out which UI element was clicked and set prefs accrdingly. This means we don't have to go back and forth between IB and PB all the time defining action methods for each checkbox.
Rick Roe
icons.cx | weblog
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 31, 2002, 05:57 AM
 
Cool! I was only farting arount with my prefs because I couldn't figure out OAPreferences. I'll check it out toot-sweet.

Hmmm. I followed the above link but I dont see the example app anywhere. I re-downloaded omniappkit thinking it may be in there, but I didnt see it. Could you please provide a direct link? Pretty please?

<small>[ 05-31-2002, 07:04 AM: Message edited by: 3R1C ]</small>
3R1C
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
May 31, 2002, 03:13 PM
 
<a href="http://www.omnigroup.com/ftp/pub/software/MacOSX/Source/Applications/" target="_blank">http://www.omnigroup.com/ftp/pub/software/MacOSX/Source/Applications/</a>
Rick Roe
icons.cx | weblog
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jun 1, 2002, 05:21 AM
 
Is there a way to limit the width of the preferences window? For instance it would be cool if I could limit the width of the preference window to the width of the widest pref pane. Beyond that it would be nice if I could limit the width of window to some arbitrary amount. As it is now, the pref window is bigger than the default state of my application window. Dont get me wrong, I dont mean to look a gift horse in the mouth, its just that I'm wondering if there is a way to change the width.
3R1C
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Jun 1, 2002, 04:11 PM
 
Currently you can't do that without changing the nib in the OmniAppKit framework. That'll probably change in the future, though.
Rick Roe
icons.cx | weblog
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jun 2, 2002, 01:15 AM
 
Im trying to implement Omni prefs but I've run into a snag. it's probably me, but I also found what I think is an inconsistency in the OmniPreferencesExample, but I'm not sure.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">To configure our preference panes, we add a top-level key, OFRegistrations, and under it, keys for each of our preference client subclasses. The dictionary for each preference pane should include the following keys and values:
snip..
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">It sounds like OFRegistrations has a child named &lt;insert name of your subclass of OAPreferenceClient&gt; who has these chilldren:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif"> • title - A title for the preference pane.
• shortTitle (Optional) - You can supply a short title to be used in places the regular one doesn't fit.
• identifier (Optional) - This is a name for the preference pane which is never made visible to the user but is used to identify the pane internally. You should use this if you're providing multiple localizations of your application.
• iconName - The name of the image file containing the pane's icon (not including filename extension).
• nibName - The name of the nib file for the panel's user interface (not including ".nib").
• defaultsDictionary (Recommended) - Instead of registering default values for each preference in your app's code, NSUserDefaults keys and values can be listed here. If your defaults are registered here, OAPreferences will make it easy for users to reset their personalized settings in each preference pane back to default values.
• defaultsArray (Optional) - If you don't register your defaults via the defaultsDictionary key, you can still make use of the "Restore Defaults" functionality by listing the NSUserDefaults keys each preference pane is responsible for here.
• category (Optional) - In an application with a large number of preference panes (such as OmniWeb), it may become useful to organize them into categories. If you create multiple categories, OAPreferences will automatically use a preferences window layout like OmniWeb's, with a "Show All" view and a toolbar for "favorite preferences".
• ordering (Optional) - If you have a small number of preference panes, OAPreferences will present them in a style similar to Mail's Preferences window, with a matrix of icons across the top which can be clicked to switch panes. Use this key to specify the order in which they should appear — lower numbers are listed first. (If you have a large number of panes or multiple categories, this key will have no effect; the "Show All" view lists them in alphabetic order, and the "favorites" toolbar is user-orderable.)
• helpURL (Optional) - If your application has Apple Help documentation, include the relative URL from your help book folder to the pane's help page here. (WARNING: in current releases of OmniAppKit, this key is optional in an all-or-nothing sense: if you include a helpURL for one pane, all other panes must have one as well.)
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">While in the info.plist of OmniPreferencesExample, OFRegistrations has a child OAPreferenceController which has a child OPEColorPreferences (mine is called DBGeneralPreferences) which has the above chilldren.

Does one only use OAPreferenceController in the info.plist if they use OFBundleRegistryConfig? The aforementioned 'snag' is that, when the application is executed, a run error occours:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif"> 2002-06-02 01:08:27.074 dasBoot[11275] OFBundleRegistry warning: registration class 'OAPrefenceController' from bundle '/Users/xaos01/Projects/Builds/dasBoot.app' not found. </font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Then, the first time the 'preferences...' menu item is selected this alert is shown:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif"> *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0) </font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">And thereafter when the 'preferences...' menu item is selected, a blank preference sized/shaped window is shown sans pref-pane views.
My initial idea is that it cant find my pref pane nib so i look in my info.plist, and its properly referenced (I guess) with my nib name without extension.

begin edit---

You know that saturday night live news skit with Gilda Radner where after this hella long spiel about something or other and at the end she sez..

"Never Mind"

OAPrefenceController != OAPreferenceController

<small>[ 06-02-2002, 06:15 AM: Message edited by: 3R1C ]</small>
3R1C
     
   
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 01:17 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