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)
发布评论