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 > How to Pass UI Object as a Parameter

How to Pass UI Object as a Parameter
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
May 22, 2003, 11:51 PM
 
Hi there. Here's a basic one.

I have a window with two NSScrollView objects. Only at runtime will the controller know which one of these views gets a message to display some text.

My design calls for passing the widget name as a parameter. How do I achieve this? Any examples or snipplets appreciated?


     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
May 23, 2003, 12:27 AM
 
Do you have IBOutlets for the views (or for the NSTextView within each, which is probably more useful, for most contexts)?

An IBOutlet connects the controller to a UI object, so the controller knows how to access that UI object.

Is this what you're asking?
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
May 23, 2003, 01:53 AM
 
I have two NSScrollViews as IBOutlets. The controller can definitely message both of these. What I need to do is target one of the NSScrollViews for a message. Which one of the two? That's two be decided at runtime.

At runtime I would like to pass the name of the targeted NSScrollView as a parameter. Something like:

If (someCondition){
targetWidgetName = ScrollView1;
}
else{
targetWidgetName = ScrollView2;
}

[targetWidgetName insertText:someString];

I'm varying not just the "insertText" argument but also the name of the object that's suppose to recieve the message.

I know I could just use something like:

If (someCondition){
[ScrollView1 insertText:someString];
}
else{
[ScrollView2 insertText:someString];
}

but I really want to use the first approach since it shows some Objective-C muscle.

I must be doing something off beat and not getting it to work -I'm really green at this.
So, I'm seeking for an example.

Thanks,
(Last edited by DaGuy; May 23, 2003 at 02:03 AM. )
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
May 23, 2003, 01:59 PM
 
Nevermind. I "sort of" got the first approach to work.

My next question is about reflection/introspection. What facilities are available in Cococa. Any good links?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 23, 2003, 03:43 PM
 
Originally posted by DaGuy:
Nevermind. I "sort of" got the first approach to work.
In what way did you not get it to work? Assuming "targetWidgetName" is an id, it should do exactly what you seem to want it to.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
May 23, 2003, 10:10 PM
 
Originally posted by Chuckit:
In what way did you not get it to work? Assuming "targetWidgetName" is an id, it should do exactly what you seem to want it to.
I drowened in a glass of water. I had a good night sleep and took a fresh look at it and corrected my missundertandings.

The "sort of" remark (made in my prior post) derives from my very green Objective-c foundations. I have some level of understanding about why the above exercise worked but nothing to write home about.

For instance:

1. Would I ever need to manually declare an IBOutlet id type or should I leave that to IB and not worry about it?

2. Why does IB need to declare widgets of type IBOutlet? Why doesn't id suffice?

Can anyone help me clear these?

Thanks!



     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
May 24, 2003, 01:54 AM
 
IBOutlet doesn't mean anything; it's not a type. It's just there so that when Interface Builder reads the header file, it knows what to show you in the Outlet part of the inspector palette.

You can also be specific about types and do:

IBOutlet NSScrollview *someScrollView;

if you want to.
[Wevah setPostCount:[Wevah postCount] + 1];
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
May 24, 2003, 10:22 AM
 
thanks that cleared things up. Now it's time to go stumble on something else!

     
   
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:34 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