Multiple text containers on layout manager and edibility

I'm trying to unpack this sentence

Note that after adding a second text container to the layout manager, the text views become uneditable and unselectable.

Found on this example code:

https://developer.apple.com/documentation/uikit/textkit/display_text_with_a_custom_layout

I'm implementing my own UITextInput which makes use of the example code setup to replicate a multi-page text editor (kind of like a basic version of Pages/Word)

Each page has its own NSTextContainer which gets added to one NSLayoutManager.

The code works and my views are rendering text across each page, however, only the first text view is editable.

It appears this is "by design" (?)

How do we get around this? Is there another level we have to drop down to enable multiple editing containers?

The sample code is wayback in iOS 13, so it would seem very odd if the capability of multiple editable text fields/containers was impossible to achieve.

Answered by DTS Engineer in 799973022

The sample code is wayback in iOS 13, so it would seem very odd if the capability of multiple editable text fields/containers was impossible to achieve.

At the time of the sample code writing, that's a limitation in TextKit. I agree though that's something to be improved, and so please feel free to file a feedback report (http://developer.apple.com/bug-reporting/) to see if the TextKit folks have something to say – If you do so, please share your report ID here.

Worth mentioning though, the Text technology has been evolving to TextKit 2 for years. You are doing a new development, and so might consider adopting TextKit2, which will make your development better future-proof.

To get started with TextKit 2, see Meet TextKit 2.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Accepted Answer

The sample code is wayback in iOS 13, so it would seem very odd if the capability of multiple editable text fields/containers was impossible to achieve.

At the time of the sample code writing, that's a limitation in TextKit. I agree though that's something to be improved, and so please feel free to file a feedback report (http://developer.apple.com/bug-reporting/) to see if the TextKit folks have something to say – If you do so, please share your report ID here.

Worth mentioning though, the Text technology has been evolving to TextKit 2 for years. You are doing a new development, and so might consider adopting TextKit2, which will make your development better future-proof.

To get started with TextKit 2, see Meet TextKit 2.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I'm working on an older project so apologies for my fuzzy memory.

I think my initial attempt was to use TextKit2 now I'm looking at the code. But there was a limit of only using one NSTextContainer.

Am I right in thinking if I wanted to create that multi-page setup I'd need each "page" to have its own layer that's drawn in to?

Similar to the Bubble TextKit2 example code does?

I found this forum post which it sounds like it was going to change to add multiple containers, So I'm quite confused in this... https://developer.apple.com/forums/thread/682251

I was under the impression the code was TextKit2 so not sure if there's an action there to make it explicit in the code example that it's outdated and using TextKit1?

You can tell that Display Text with a Custom Layout is a TextKit1 sample because it explicitly uses NSLayoutManager here and there. When you use the layoutManager property of a text view, the system automatically falls back to TextKit1. This was mentioned in Meet TextKit 2.

Am I right in thinking if I wanted to create that multi-page setup I'd need each "page" to have its own layer that's drawn in to?

Not necessarily to have one layer for each page, but you will need to manage the page separator / frame with your own code. The Using TextKit 2 to interact with text sample has one layer per paragraph (NSTextElement), btw.

I found this forum post which it sounds like it was going to change to add multiple containers, So I'm quite confused in this... https://developer.apple.com/forums/thread/682251

As of today, NSTextLayoutManager (TextKit2) still doesn't support multiple containers.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Multiple text containers on layout manager and edibility
 
 
Q