问题
I need to create a NSMutableAttributedString with different CTFontRef and CTParagraphStyleRef for different range in that string.
I try creating it by putting the following code in a loop and change range as I need,
CTFontRef normalFontRef = CTFontCreateWithName((CFStringRef)@"CourierNewPSMT", fontsize, NULL);
NSDictionary* normalFontAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)normalFontRef,(NSString*)kCTFontAttributeName, nil];
[attributedString addAttributes:normalFontAttribute range:range];
CFRelease(normalFontRef);
[normalFontAttribute release];
normalFontAttribute = nil;
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
NSDictionary* paragraphAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)paragraphStyle,(NSString*)kCTParagraphStyleAttributeName, nil];
[attributedString addAttributes:paragraphAttribute range:range];
CFRelease(paragraphStyle);
paragraphAttribute release];
paragraphAttribute = nil;
My Problem is:
The App crashes in device after some iteration of loop with out showing any details. Just close the app no crash report, no message in console, no gdb break point.
More Explanations: I call this NSMutableAttributedString creation method in another loop for some other processing, That loop is the crashed loop, not the NSMutableAttributedString creation loop. But if I commented calling the above method and use create a NSMutableAttributedString it works fine, see below
//works fine
attributtedString = [[NSMutableAttributedString alloc] initWithString:stringContent];
//not working
attributtedString = [self createattributtedString:stringContent];
//this createattributtedString: method contain the first listed code
thanks in advance,
回答1:
You might have an endless loop.
来源:https://stackoverflow.com/questions/6345780/problem-while-using-ctfontref-in-a-loop-to-create-nsmutableattributedstring