2012-01-18 2 views
0

정상적인 문자열에서 속성이 지정된 문자열을 생성하는 방법을 만들었습니다. 아래의 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)}"; }

+0

메모리 누수를 피하려면 여기'bridge "를 사용해야합니다. NSLog ("% @", attrString)'가 출력되면 무엇입니까? 출력을 질문에 붙여 넣으십시오. –

+0

@rob 응답 해 주셔서 감사합니다. 요청한대로 완료했습니다. 위를 참조하십시오. – KomodoDave

+0

죄송합니다, 나는'NSLog (@ "% @", attrString)'라고 말해야했습니다. 하지만 당신이 한 일은 괜찮습니다. –

답변

8

내가 발견 귀속 문자열 덤프 :

NSFont = "<CGFont (0x28f850): ArialMT>" 

kCTFontAttributeName 키의 값으로 CGFontRef을 사용하여 특성 문자열을 만들었습니까? CGFontRef이 아닌 CTFontRef을 사용해야합니다. 그들은 다르다.

+0

저는 지금 일하고 있지만 8 시간 내에 집에 왔을 때 다시 확인하고 다시 응답 할 것입니다. 제안을 위해 많이 고마워하고 그 발견을 위해 잘 했어, 나는 네가 맞다고 내기를 :-) 나는 그들이 다르다는 것을 알고 있지만 CATextLayer 서브 클래스에서 자동으로 'attributeString'메소드를 가졌다. CTFont '글꼴'속성 및 나는 실수로 생성자 (모두 해당 속성에 대해 허용되는) CGFont 설정했습니다 내기. – KomodoDave

+0

당신이 맞았 어. Rob,이 방법은 완벽하게 작동합니다 .--) 시간을내어 반응 해 주셔서 대단히 감사합니다. 실수를 저지르는 데 더 오래 걸렸을 것입니다. 엄지 위로! – KomodoDave

+0

이 정확한 문제가 있었고 UIFont와 UIColor 객체를 모두 넣었습니다. 그래서이 문제가 해결되면서 감사드립니다. – drekka

관련 문제