2016-06-21 3 views
-1

У меня есть UITextView, который будет иметь смесь изображений (как NSTextAttachment) и символьных строк. UITextView НЕ выбирается, так что я могу использовать:Удалить/Удалить NSTextAttachment из UITextView

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

Как удалить textAttachment в методе?

+0

'NSMutableAttributedString * mutableAttr = [[TextView attributedText] mutableCopy]; [mutableAttr replaceCharactersInRange: range withString: @ ""]; [textView setAttributedText: mutableAttr]; '? – Larme

+0

потрясающий! опубликуйте это как решение, и я его приму – Gukki5

ответ

1

Вы можете использовать replaceCharactersInRange:withString: из NSMutableAttributedString для удаления прикрепленного (вы получили диапазон в качестве параметра метода UITextViewDelegate):

//Retrieve the attributed string 
NSMutableAttributedString *mutableAttr = [[textView attributedText] mutableCopy]; 
//Remove the attachment 
[mutableAttr replaceCharactersInRange:range withString:@""]; 
//Set the new attributed string 
[textView setAttributedText:mutableAttr]; 
Смежные вопросы