0

I have an NSTextField subclass (called "txtField1" and used as Custom Class for a Text Field in my interface builder) and I would like to be able to access an NSComboBox object which present in my interface builder from this class.

This is my code: txtField1.h:

#import <Cocoa/Cocoa.h>

@interface txtField1 : NSTextField

@end

txtField.m:

#import "txtField1.h"

@implementation txtField1

-(void)mouseDown:(NSEvent *)theEvent
{
    HERE I would like to be able to write something like:
    [combobox SetHidden:YES];
}

@end

I would like to be able to set access the combobox SetHidden property, in the mouseDown event. Can you please tell me how to do that? I have tried different solutions found on internet but didn't obtain anything at all! Any help would be appreciated.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
rambodrahmani
  • 99
  • 4
  • 12

2 Answers2

1

Here are a lot of ways, and answers here, to do :

Update a label through button from different view

Xcode - update ViewController label text from different view

Setting label text in another class

Set label on another view to stored NSDate

EDIT:

-(void)mouseDown:(NSEvent *)theEvent
{
    HERE I would like to be able to write something like:
    [combobox SetHidden:YES];
    /*
        use the shared instance of comboBox here and make it hidden.
        Also, you can use binding to make it hidden
    */
}
Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • Sorry but actually none of the answers you suggested helped me. Can you please make me an example? – rambodrahmani Mar 04 '13 at 17:42
  • `access an NSComboBox object which present in my interface builder from this class.` in which class, it is? – Anoop Vaidya Mar 04 '13 at 17:44
  • "use the shared instance of comboBox here and make it hidden." Can you please make me an example of code since I am a newbie in cocoa programming? thank you. – rambodrahmani Mar 04 '13 at 18:34
  • Any idea? I'll try to explain you all what I'm trying to do again: I have an NSTextfield and an NSComboBox. Well I want the NSTextField to disappear and the NSComboCox to appear when some one clicks inside the NSTextField. Help me. Thank you. – rambodrahmani Mar 05 '13 at 17:47
  • have a look here please: http://stackoverflow.com/questions/15248130/make-nscombobox-appear-when-nstextfield-is-clicked – rambodrahmani Mar 06 '13 at 19:13
0

From my point of view txtField1 class is not better place to this code.

You can add NSControlTextEditingDelegate protocol to your NSViewController implementation (that already contains IBOutlets for txtField1 and combobox) and in method – control:textView:doCommandBySelector: implement hiding of your NSComboBox

CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
  • Any idea? I'll try to explain you all what I'm trying to do again: I have an NSTextfield and an NSComboBox. Well I want the NSTextField to disappear and the NSComboCox to appear when some one clicks inside the NSTextField. Help me. Thank you. – rambodrahmani Mar 05 '13 at 17:46
  • have a look here please: http://stackoverflow.com/questions/15248130/make-nscombobox-appear-when-nstextfield-is-clicked – rambodrahmani Mar 06 '13 at 19:14