Problem while using CTFontRef in a loop to create NSMutableAttributedString

有些话、适合烂在心里 提交于 2019-12-12 09:17:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!