정상적인 문자열에서 속성이 지정된 문자열을 생성하는 방법을 만들었습니다. 아래의 attrString
값은 null이 아니며 내용이 정확합니다.iOS : CTFramesetterCreateWithAttributedString으로 인해 EXC_BAD_ACCESS가 발생합니다. 그 이유는 무엇입니까?
내 응용 프로그램을 실행할 때 두 번째 줄은 EXC_BAD_ACCESS
으로 실패합니다. 왜 그런가?
__bridge_retained
전화는 iOS 5 요구 사항 afaik입니다. 나는 또한 __bridge
을 시도했지만 아무런 효과가 없지만 여전히 문제가 발생합니다.
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge_retained CFMutableAttributedStringRef)attrString);
UPDATE
내가 할 경우
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
NSLog(@"%@", attrString);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attrString);
그런 다음 NSLog
라인이 컴파일되지 않습니다; Xcode는 "Incompatible pointer types passing 'char[3]' to parameter of type 'NSString *'"
을 나타내는 오류 및을 제공합니다.를 (I 개인 정보 보호에 대한 <snipped>
와 문자열 내용을 대체 한)
NSLog([attrString description]);
을 그리고 이것은 다음과 같은 출력 을 제공합니다 :
그래서 내가 대신이 시도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)}"; }
메모리 누수를 피하려면 여기'bridge "를 사용해야합니다. NSLog ("% @", attrString)'가 출력되면 무엇입니까? 출력을 질문에 붙여 넣으십시오. –
@rob 응답 해 주셔서 감사합니다. 요청한대로 완료했습니다. 위를 참조하십시오. – KomodoDave
죄송합니다, 나는'NSLog (@ "% @", attrString)'라고 말해야했습니다. 하지만 당신이 한 일은 괜찮습니다. –