2016-06-21 11 views
-1

UITextViewには、画像(NSTextAttachment)と文字列が混在しています。 UITextViewは選択できませんので、私は使用することができます。UITextViewからNSTextAttachmentを削除/削除する

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

あなたは添付ファイルを削除するにはNSMutableAttributedStringreplaceCharactersInRange:withString:を使用することができます(あなたが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]; 
関連する問題