UITextView撤消管理器不适用于替换属性字符串(iOS 6)

编程入门 行业动态 更新时间:2024-10-25 18:23:19
本文介绍了UITextView撤消管理器不适用于替换属性字符串(iOS 6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

iOS 6已经更新为使用UITextView进行富文本编辑(UITextView现在可以获得一个属性非文本的属性 - 这是非常可变的 - )。这是在NDA上的iOS 6 Apple论坛上提出的一个问题,可以公开,因为iOS 6现已公开...

iOS 6 has been updated to use UITextView for rich text editing (a UITextView now earns an attributedText property —which is stupidly non mutable—). Here is a question asked on iOS 6 Apple forum under NDA, that can be made public since iOS 6 is now public...

在UITextView中,我可以撤消任何字体更改但无法撤消视图的属性字符串副本中的替换。使用此代码时...

In a UITextView, I can undo any font change but cannot undo a replacement in a copy of the view's attributed string. When using this code...

- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new { 1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old]; 2. old=new; }

...撤消工作正常。

... undoing is working well.

但是如果我添加一行来在我的视图中看到结果,则undoManager不会触发replace:with:方法,因为它应该......

But if I add a line to get the result visible in my view, the undoManager do not fire the "replace:with:" method as it should...

- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new { 1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old]; 2. old=new; 3. myView.attributedText=[[NSAttributedString alloc] initWithAttributedString:old]; }

有什么想法吗?我有任何替换方法的问题,使用范围与否,MutableAttributedString我试图在线2...

Any idea? I have the same problem with any of the replacement methods, using a range or not, for MutableAttributedString I tried to use on line "2"...

推荐答案

嗯,哇,我真的不希望这个工作!我找不到解决方案,所以我开始尝试任何事情......

Umm, wow I really didn't expect this to work! I couldn't find a solution so I just started trying anything and everything...

- (void)applyAttributesToSelection:(NSDictionary*)attributes { UITextView *textView = self.contentCell.textView; NSRange selectedRange = textView.selectedRange; UITextRange *selectedTextRange = textView.selectedTextRange; NSAttributedString *selectedText = [textView.textStorage attributedSubstringFromRange:selectedRange]; [textView.undoManager beginUndoGrouping]; [textView replaceRange:selectedTextRange withText:selectedText.string]; [textView.textStorage addAttributes:attributes range:selectedRange]; [textView.undoManager endUndoGrouping]; [textView setTypingAttributes:attributes]; }

更多推荐

UITextView撤消管理器不适用于替换属性字符串(iOS 6)

本文发布于:2023-11-27 05:08:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636726.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   字符串   属性   不适用于   UITextView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!