Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从UITextView中删除/删除NSTextAttachment_Ios_Uitextview_Nstextattachment - Fatal编程技术网

Ios 从UITextView中删除/删除NSTextAttachment

Ios 从UITextView中删除/删除NSTextAttachment,ios,uitextview,nstextattachment,Ios,Uitextview,Nstextattachment,我有一个UITextView,它将混合使用图像(如NSTextAttachment)和字符串。无法选择UITextView,因此我可以使用: - (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange 如何删除方法中的textAttachment?您可以使用NSMutable

我有一个
UITextView
,它将混合使用图像(如
NSTextAttachment
)和字符串。无法选择
UITextView
,因此我可以使用:

- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange 

如何删除方法中的
textAttachment

您可以使用
NSMutableAttributedString的
replaceCharactersRange:withString:
删除附件(范围作为
UITextViewDelegate
方法的参数):


您可以使用
NSMutableAttributedString
replaceCharactersRange:with字符串:
删除附件(范围作为
UITextViewDelegate
方法的参数):


NSMutableAttributedString*mutableAttr=[[textView attributedText]mutableCopy];[mutableAttr ReplaceCharactersRange:带有字符串的范围:@”“;[textView setAttributedText:mutableAttr]?太棒了!将此作为解决方案发布,我将接受它
NSMutableAttributedString*mutableAttr=[[textView attributedText]mutableCopy];[mutableAttr ReplaceCharactersRange:带有字符串的范围:@”“;[textView setAttributedText:mutableAttr]?太棒了!将此作为解决方案发布,我将接受它
//Retrieve the attributed string
NSMutableAttributedString *mutableAttr = [[textView attributedText] mutableCopy];
//Remove the attachment
[mutableAttr replaceCharactersInRange:range withString:@""]; 
//Set the new attributed string
[textView setAttributedText:mutableAttr];