Closed pepicrft closed 7 years ago
Hi @pepibumur
in the sample project I've assigned the layoutManager
after setting the attributed string to avoid the crash.
I'm still going to try to solve the issue, but for now can you to switch the rows?
// Load a sample markdown content from a file inside the app bundle
if let samplePath = NSBundle.mainBundle().pathForResource("Sample", ofType: "md"){
do {
let string = try String(contentsOfFile: samplePath)
// Convert string to an `NSAttributedString`
let attributedString = NSAttributedString(string: string)
// Set the loaded string to the `UITextView`
textView.attributedText = attributedString
// Append the loaded string to the `NSTextStorage`
textStorage.appendAttributedString(attributedString)
} catch _ {
print("Cannot read Sample.md file")
}
}
// Assign the `UITextView`'s `NSLayoutManager` to the `NSTextStorage` subclass
textStorage.addLayoutManager(textView.layoutManager)
It works @macteo , thanks a lot :P
Thanks for your feedback! BTW great app and interface.
thanks @macteo
I think setting the attributedText
or text
directly on a UITextView
is actually meaningless when you're providing your own NSTextStorage
, since the text view no longer owns its own storage. If you never access attributedText
/text
directly, but instead do textStorage.setAttributedString(myAttributedString)
, everything should work fine.
(At least, it works for me. Correct me if I'm wrong about this!)
@pepibumur random question, but do you happen to be using RFKeyboardToolbar?
I'm closing it based on @sadlerjw consideration.
When I try to set the content the application crashes. This is how I set it:
Before I've initialized the MarklightTextStorage and add the layout manager. This is the crash I got:
Am I doing anything wrong? Thanks!