NSString コンテンツを含む段落の NSOrderedSet があります。すべてをループすると、大きな文字列が作成され、NSTextStorage が与えられます。しかし、それですべての段落が失われます。
以下のコードを使用すると、ページを数えてコンテンツをページ単位で表示できます。しかし、コンテンツを段落に分けて、ユーザーが特定の段落をいつタップしたかを知りたいです。
NSTextStorage を使用して、コンテンツを単一の大きな文字列としてではなく、小さなテキスト ブロックのコレクションとして表示するにはどうすればよいですか? 注: UIPageViewController を使用してコンテンツを表示しているため、ページごとの段落数も知る必要があります。
NSString *content = @"";
for (TWParagraph *paragraph in self.bookParagraphs)
{
TWTextBlock *textBlock = paragraph.hasTextBlock.firstObject;
content = [content stringByAppendingString:textBlock.textContent];
}
NSTextStorage *localTextStorage = [[NSTextStorage alloc] initWithString:content];
NSLayoutManager *localLayoutManager = [NSLayoutManager new];
NSTextContainer *localTextContainer = [self createTextContainer];
localLayoutManager.delegate = self;
[localTextStorage addLayoutManager:localLayoutManager];
[localLayoutManager addTextContainer:localTextContainer];
[localLayoutManager ensureLayoutForTextContainer:localTextContainer];
self.numberOfPages = [[localLayoutManager textContainers] count];
ありがとう。