Mam NSTextView. Wklejam obraz i widzę go. Kiedy otrzymam NSTextAttachment dla NSAttributedString widoku tekstowego, jego plik jest zerowy. Jak uzyskać dane obrazu wklejone w widoku tekstowym?Jak uzyskać dane obrazu z NSAttributedString
Używam kategorii na NSAttributedString, aby uzyskać załączniki tekstowe. Wolałbym nie pisać na dysk, jeśli to możliwe.
- (NSArray *)allAttachments
{
NSError *error = NULL;
NSMutableArray *theAttachments = [NSMutableArray array];
NSRange theStringRange = NSMakeRange(0, [self length]);
if (theStringRange.length > 0)
{
NSUInteger N = 0;
do
{
NSRange theEffectiveRange;
NSDictionary *theAttributes = [self attributesAtIndex:N longestEffectiveRange:&theEffectiveRange inRange:theStringRange];
NSTextAttachment *theAttachment = [theAttributes objectForKey:NSAttachmentAttributeName];
if (theAttachment != NULL){
NSLog(@"filewrapper: %@", theAttachment.fileWrapper);
[theAttachments addObject:theAttachment];
}
N = theEffectiveRange.location + theEffectiveRange.length;
}
while (N < theStringRange.length);
}
return(theAttachments);
}
można dodać kod pokazujący, co robisz, jak się próbuje uzyskać dostęp do danych obrazu itd dokładnie Bez takich informacji ludzie, którzy próbują ci pomóc, po prostu zgadują. – CRD