May I indulge the group.

In doing the Hillegass challenge of Chapter 18 ( creating a doc based app to draw ovals), detoured to get a deeper understanding to Apples Sketch-112, which in turn lead to properties and ivars, which lead to this little demo app to give me some more insight into how properties and ivars worked. The problem I have is that I cannot set a label programmatically....and am not sure if this is related to my understanding of properties, or my understanding of the workings of an NSTExtField. ( I did a search of this site, tried, "validateEditing" but still could not prevail. )


Basically, a non-doc app, with an NSTextField ( whose initial title is "label"), an AppController with an IBOutlet ( textField), and with AppController's outlet to NSTextField's control connection established in the nib.

The relevant code in AppController.h thus.



@interface AppController : NSObject {
        
        NSTextField * _textField;

}

@property (readwrite, retain) IBOutlet NSTextField *textField;


The accessors like this. ( I know that I could have used @synthesize) but I wanted to see what was happening in the code.


- (NSTextField*) textField
{
METHOD_LOG;// << A macro which reveals method's name, and the object (self) >>
        NSLog(@"%@", _textField);
        return _textField;
}

- (void) setTextField: (NSTextField*) t
{
        METHOD_LOG;
        if ( _textField == t)
                return;
        [_textField release];
        [t retain];
        _textField = t;
NSLog(@"The value of TextField \"_textField\" is: %@",[_textField stringValue]);
        
        // this line a test to see if "validateEditing" works
        
        [_textField validateEditing];  // does not effect outcome
        
}


and finally, in awakeFromNib, this;


        METHOD_LOG;
         NSColor * g = [ NSColor greenColor];
         NSString *s = @"FooBar";
         NSTextField *f = [[NSTextField alloc]init];
         [f setBackgroundColor:g];
         [f setStringValue:s];
         NSLog(@"The value of TextField \"f\" is: %@",[f stringValue]);
         [self setTextField: f];
        [f release];


My output is this: (which includes a warning, which is probably relevant, but I have not been able to find much on it);



 MethodName: setTextField: "self" = <AppController: 0x1002140d0>
The value of TextField "_textField" is: label
MethodName: awakeFromNib "self" = <AppController: 0x1002140d0>
The value of TextField "f" is: FooBar
MethodName: setTextField: "self" = <AppController: 0x1002140d0>
The value of TextField "_textField" is: FooBar
__CFServiceControllerBeginPBSLoadForLocalizations timed out while talking to pbs


So, from my reading of ivars, properties and outlets, it seems that Apple now recommends that the properties (not the ivars ) be exposed, which I have tried to do. Also, from the output in the console, it seems as if the outlet is set, but then reverts back to the word "label". Some insight would be appreciated. (It might very well be that this involves something that is yet to be covered, and if so, I will move on. But, just wish to know if this is something obvious that I have missed).
Thanks as always.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to