Cannot affect UITextView contents with initWithCoder

I am trying to get the string displayed in mine UITextViewat the time the application starts. I have UIViewand UITextViewmy interface and one output myText, which is connected to UITextView. It does not seem to work, and I cannot 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

A message has been sent NSLog(), so I assume it is myText.textreally set to @"Hello World", but this is not reflected in mine UITextView. Where to hang up here? If that helps, this is a simplified version of my actual application, and when I put the same one myText.text = @"Hello, World!";in a method that responds to a button click, the change is reflected in the text view.

+3
1

Nib initWithCoder: - , , , nib . awakeFromNib.

+6

Source: https://habr.com/ru/post/1732808/


All Articles