J'ai créé une méthode pour générer une chaîne attribuée à partir d'une chaîne normale. La valeur attrString
ci-dessous est non nulle et correcte dans son contenu.iOS: CTFramesetterCreateWithAttributedString provoque EXC_BAD_ACCESS, pourquoi?
Lors de l'exécution de mon application, la deuxième ligne échoue avec un EXC_BAD_ACCESS
. Une idée pourquoi?
L'appel __bridge_retained
est une condition requise pour iOS 5. J'ai également essayé __bridge
mais cela n'a aucun effet, le problème se produit toujours.
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge_retained CFMutableAttributedStringRef)attrString);
MISE À JOUR
Si je fais:
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
NSLog(@"%@", attrString);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attrString);
Ensuite, la ligne NSLog
ne compilera pas; Xcode donne un avertissement et erreur indiquant "Incompatible pointer types passing 'char[3]' to parameter of type 'NSString *'"
.
donc j'ai essayé ceci:
NSLog([attrString description]);
Et cela donne la sortie suivante (je l'ai remplacé le contenu de la chaîne avec <snipped>
de la vie privée):
2012-01-19 06:49:11.307 WritePath[2475:707] <Snipped> { CTForegroundColor = "<CGColor 0x281530> [<CGColorSpace 0x22d1a0> (kCGColorSpaceDeviceRGB)] (0 0 0 1)"; NSFont = "<CGFont (0x28f850): ArialMT>"; NSParagraphStyle = "CTParagraphStyle:\nwriting direction = -1, alignment = 3, line break mode = 0, default tab interval = 0\nfirst line head indent = 0, head indent = 0, tail indent = 0\nline height multiple = 0, maximum line height = 0, minimum line height = 0\nline spacing adjustment = 0, paragraph spacing = 0, paragraph spacing before = 0\ntabs:\n<CFArray 0x287b50 [0x3f229630]>{type = immutable, count = 12, values = (\n\t0 : CTTextTab: location = 28, alignment = 0, options = (none)\n\n\t1 : CTTextTab: location = 56, alignment = 0, options = (none)\n\n\t2 : CTTextTab: location = 84, alignment = 0, options = (none)\n\n\t3 : CTTextTab: location = 112, alignment = 0, options = (none)\n\n\t4 : CTTextTab: location = 140, alignment = 0, options = (none)\n\n\t5 : CTTextTab: location = 168, alignment = 0, options = (none)\n\n\t6 : CTTextTab: location = 196, alignment = 0, options = (none)\n\n\t7 : CTTextTab: location = 224, alignment = 0, options = (none)\n\n\t8 : CTTextTab: location = 252, alignment = 0, options = (none)\n\n\t9 : CTTextTab: location = 280, alignment = 0, options = (none)\n\n\t10 : CTTextTab: location = 308, alignment = 0, options = (none)\n\n\t11 : CTTextTab: location = 336, alignment = 0, options = (none)\n\n)}"; }
Vous devriez utiliser '__bridge' ici pour éviter une fuite de mémoire. Quelle est la sortie si vous 'NSLog ("% @ ", attrString)'? Collez la sortie dans votre question. –
@rob Merci d'avoir répondu - J'ai fait ce que vous avez demandé, voir ci-dessus. – KomodoDave
Désolé, j'aurais dû dire 'NSLog (@"% @ ", attrString)'. Mais ce que tu as fait est ok. –