使用CTFontRef在循环中创建NSMutableAttributedString时出现问题 [英] Problem while using CTFontRef in a loop to create NSMutableAttributedString

查看:192
本文介绍了使用CTFontRef在循环中创建NSMutableAttributedString时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为该字符串中不同的范围创建一个具有不同CTFontRef和CTParagraphStyleRef的NSMutableAttributedString。

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;

我的问题是

应用程序在一些迭代循环后显示任何细节,设备崩溃。
只需关闭应用程序,没有崩溃报告,控制台中没有消息,没有gdb断点。

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.

更多说明:
我在另一个循环中将此NSMutableAttributedString创建方法称为其他处理,该循环是崩溃循环,而不是NSMutableAttributedString创建循环。但如果我评论调用上述方法并使用创建一个NSMutableAttributedString它工作正常,请参见下面

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 

p>

推荐答案

你可能有一个无尽的循环。

You might have an endless loop.

这篇关于使用CTFontRef在循环中创建NSMutableAttributedString时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆