iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了UITextView撤消管理器不适用于替换属性字符串(iOS 6)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
iOS 6已更新为使用UITextView进行富文本编辑(UITextView现在可以获属性文本属性 – 这是非常不可变的 – ).这是在NDA下的iOS 6 Apple论坛上提出的一个问题,可以公开,因为iOS 6现已公开…

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

- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new

{
1.    [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old];
2.    old=new;

}

…撤消工作正常.

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

- (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”

解决方法

嗯,哇,我真的没想到这个工作我找不到解决方案,所以我开始尝试任何事情……

- (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)全部内容,希望文章能够帮你解决UITextView撤消管理器不适用于替换属性字符串(iOS 6)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。