views:

148

answers:

1

I'm trying to get a string displayed in my UITextView the moment the app is launched. I have a UIView and (obviously) a UITextView in my interface, and one outlet, myText, which is connected to the UITextView. It doesn't seem to be working and I can't say why....

Here is the code in question:

MainView.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {

    IBOutlet UITextView *myText;

}
@end

MainView.m

@implementation MainView

-(id) initWithCoder:(NSCoder *)coder {


    if ((self = [super initWithCoder:coder]) != nil)
    {
        NSLog(@"initWithCoder executed");
        myText.text = @"Hello, World!";
    }

    return self;
}

@end

The NSLog message is logged, so I assume that that myText.text is indeed set to "Hello World", but this isn't reflected in my UITextView. Where is the hang up here? If it helps, this is a simplified version of my actual app, and when I put that same myText.text = @"Hello, World!"; into a method that responds to a button press, the change is reflected in UITextView. I'm anticipating this is some simple thing I'm missing...

Any help is appreciated! Thanks!

+2  A: 

Nib connections are not necessarily there in initWithCoder: — just because this object has been unfrozen doesn't mean everything else in the nib has been. You want awakeFromNib.

Chuck
Excellent! Thank you very much! Everybody here is amazingly helpful. As always, thanks for taking the time to help newbie!
Arthur Skirvin
*a newbie. My mistake. Since I'm a newbie...
Arthur Skirvin