0

I wonder why my delegate method

- (void)layoutManager:(NSLayoutManager *)layoutManager
didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer
                atEnd:(BOOL)layoutFinishedFlag

not called, i used this code:

self.storage = [[NSTextStorage alloc] initWithString:@"sdfsdf sdf sdf sdf sdf sdf Sdf sdf sdf "];
self.layout = [[NSLayoutManager alloc] init];
[self.storage addLayoutManager:self.layout];
self.layout.delegate = self;
NSTextContainer * container = [[NSTextContainer alloc] init];
[self.layout addTextContainer:container];

TextStorage and LayoutManager properties are strong retained in the class, but delegate method not called!!!

Yasser Farrag
  • 307
  • 2
  • 12

2 Answers2

0

The delegate method will be called when you modify the NSTextStorage after setting the delegate. This is a snippet from a UIViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.layout = [[NSLayoutManager alloc] init];
    self.layout.delegate = self;
    self.storage = [[NSTextStorage alloc] init];
    [self.storage addLayoutManager:self.layout];
    NSTextContainer * container = [[NSTextContainer alloc] init];
    [self.layout addTextContainer:container];
    NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"New string"];
    [self.storage setAttributedString:string];
}

- (void)layoutManager:(NSLayoutManager *)layoutManager
didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer
                atEnd:(BOOL)layoutFinishedFlag
{
    NSLog(@"I'm here");
}
Fabio Felici
  • 2,841
  • 15
  • 21
0

I found that delegate method also called when you add any container to UITextView.

Yasser Farrag
  • 307
  • 2
  • 12